app/Http/Controllers/Admin/StatesController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\State  $state
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, State $state)
    {
        if (Gate::denies('manage-system')) {
            return redirect()->route('admin.states.edit')->with('state', $state);
        }
        $validator = Validator::make($request->all(), [
            'name'  => ['required', 'string', 'min:3', "max:128"],
            'code'  => ['nullable', 'string'],
        ]);
        if ($validator->fails())
        {
            $request->session()->flash('error', $validator->messages()->first());
            return redirect()->route('admin.states.edit', $state);
        }
        $data = $request->all();
        $state->name = $data['name'];
        $state->code = $data['code'];
        if(!$state->save()) {
            $request->session()->flash('error', 'There is an error modifying Province/State!');
            return redirect()->route('admin.states.edit', $state);
        }
        $request->session()->flash('success', 'You have modified Province/State!');
        return redirect()->route('admin.states.index');
    }
public function update ( Request $ request , State $ state ) { if ( Gate :: denies ( 'manage-system' ) ) { return redirect ( ) -> route ( 'admin.states.edit' ) -> with ( 'state' , $ state ) ; } $ validator = Validator :: make ( $ request -> all ( ) , [ 'name' => [ 'required' , 'string' , 'min:3' , " max:128 " ] , 'code' => [ 'nullable' , 'string' ] , ] ) ; if ( $ validator -> fails ( ) ) { $ request -> session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( ) -> route ( 'admin.states.edit' , $ state ) ; } $ data = $ request -> all ( ) ; $ state -> name = $ data [ 'name' ] ; $ state -> code = $ data [ 'code' ] ; if ( ! $ state -> save ( ) ) { $ request -> session ( ) -> flash ( 'error' , 'There is an error modifying Province/State!' ) ; return redirect ( ) -> route ( 'admin.states.edit' , $ state ) ; } $ request -> session ( ) -> flash ( 'success' , 'You have modified Province/State!' ) ; return redirect ( ) -> route ( 'admin.states.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .