app/Http/Controllers/Admin/InformationsController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Information  $information
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, Information $information)
    {
        if (Gate::denies('manage-cms')) {
            return redirect()->route('admin.informations.edit')->with('information', $information);
        }
        $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.edit', $information);
        }
        $data = $request->all();
        $information->title = $data['title'];
        $information->description = $data['description'];
        if (isset($data['status'])) $information->status = $data['status'];
        $urlalias = UrlAlias::whereRaw("query like 'information_id=" . $information->id . "'")->first();
        if (isset($data['keyword'])) {
            if ($urlalias != NULL) $urlalias->delete();
            UrlAlias::create([
                'query'     => "information_id=" . $information->id,
                'keyword'   => $data['keyword']
            ]);
        }
        if(!$information->save()) {
            $request->session()->flash('error', 'There is an error modifying information!');
            return redirect()->route('admin.informations.edit', $information);
        }
        $request->session()->flash('success', 'You have modified information!');
        return redirect()->route('admin.informations.index');
    }
public function update ( Request $ request , Information $ information ) { if ( Gate :: denies ( 'manage-cms' ) ) { return redirect ( ) -> route ( 'admin.informations.edit' ) -> with ( 'information' , $ information ) ; } $ 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.edit' , $ information ) ; } $ data = $ request -> all ( ) ; $ information -> title = $ data [ 'title' ] ; $ information -> description = $ data [ 'description' ] ; if ( isset ( $ data [ 'status' ] ) ) $ information -> status = $ data [ 'status' ] ; $ urlalias = UrlAlias :: whereRaw ( " query like 'information_id= " . $ information -> id . " ' " ) -> first ( ) ; if ( isset ( $ data [ 'keyword' ] ) ) { if ( $ urlalias != NULL ) $ urlalias -> delete ( ) ; UrlAlias :: create ( [ 'query' => " information_id= " . $ information -> id , 'keyword' => $ data [ 'keyword' ] ] ) ; } if ( ! $ information -> save ( ) ) { $ request -> session ( ) -> flash ( 'error' , 'There is an error modifying information!' ) ; return redirect ( ) -> route ( 'admin.informations.edit' , $ information ) ; } $ request -> session ( ) -> flash ( 'success' , 'You have modified information!' ) ; return redirect ( ) -> route ( 'admin.informations.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .