app/Http/Controllers/Admin/InformationsController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        if (Gate::denies('manage-cms')) {
            return redirect()->route('admin.informations.create');
        }
        $validator = Validator::make($request->all(), [
            'title'        => ['required', 'string'],
            'description'  => ['required', 'string'],
            'status'       => ['nullable', 'integer'],
        ]);
        if ($validator->fails())
        {
            $request->session()->flash('error', $validator->messages()->first());
            return redirect()->route('admin.informations.create');
        }
        $data = $request->all();
        $information = Information::create([
            'title'         => $data['title'],
            'description'   => $data['description'],
            'status'        => $data['status']
        ]);
        if($information == NULL) {
            $request->session()->flash('error', 'There is an error creating information!');
            return redirect()->route('admin.informations.create');
        }
        if (isset($data['keyword'])) {
            UrlAlias::create([
                'query'     => "information_id=" . $information->id,
                'keyword'   => $data['keyword']
            ]);
        }
        $request->session()->flash('success', 'You have created information!');
        return redirect()->route('admin.informations.index');
    }
public function store ( Request $ request ) { if ( Gate :: denies ( 'manage-cms' ) ) { return redirect ( ) -> route ( 'admin.informations.create' ) ; } $ validator = Validator :: make ( $ request -> all ( ) , [ 'title' => [ 'required' , 'string' ] , 'description' => [ 'required' , 'string' ] , 'status' => [ 'nullable' , 'integer' ] , ] ) ; if ( $ validator -> fails ( ) ) { $ request -> session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( ) -> route ( 'admin.informations.create' ) ; } $ data = $ request -> all ( ) ; $ information = Information :: create ( [ 'title' => $ data [ 'title' ] , 'description' => $ data [ 'description' ] , 'status' => $ data [ 'status' ] ] ) ; if ( $ information == NULL ) { $ request -> session ( ) -> flash ( 'error' , 'There is an error creating information!' ) ; return redirect ( ) -> route ( 'admin.informations.create' ) ; } if ( isset ( $ data [ 'keyword' ] ) ) { UrlAlias :: create ( [ 'query' => " information_id= " . $ information -> id , 'keyword' => $ data [ 'keyword' ] ] ) ; } $ request -> session ( ) -> flash ( 'success' , 'You have created information!' ) ; return redirect ( ) -> route ( 'admin.informations.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .