app/Http/Controllers/UseCRUDController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
        $user = User::find($id);
        $data = $request->all();
        $this ->validate($request,[
            'username' => 'required|string|max:255',
            'firstname' => 'required|string|max:255',
            'lastname' => 'required|string|max:255',
            ]);
        Validator::make($data, [
            'email' => [
            'required',
            Rule::unique('users')->ignore($user->id),
            ],
            ]);
        $user = User::find($id);
        $user->username = $request->input('username');
        $user->firstname = $request->input('firstname');
        $user->lastname = $request->input('lastname');
        $user->email = $request->input('email');
        if($request->password!=null){
            $this->validate($request,[
                'password' => 'string|min:6',
                ]);
            $user->password = bcrypt($request->input('password'));
        }       
        $user->save();
        return redirect()->route('admin.home')->with('status', 'User updated!');
    }
public function update ( Request $ request , $ id ) { $ user = User :: find ( $ id ) ; $ data = $ request -> all ( ) ; $ this -> validate ( $ request , [ 'username' => 'required|string|max:255' , 'firstname' => 'required|string|max:255' , 'lastname' => 'required|string|max:255' , ] ) ; Validator :: make ( $ data , [ 'email' => [ 'required' , Rule :: unique ( 'users' ) -> ignore ( $ user -> id ) , ] , ] ) ; $ user = User :: find ( $ id ) ; $ user -> username = $ request -> input ( 'username' ) ; $ user -> firstname = $ request -> input ( 'firstname' ) ; $ user -> lastname = $ request -> input ( 'lastname' ) ; $ user -> email = $ request -> input ( 'email' ) ; if ( $ request -> password != null ) { $ this -> validate ( $ request , [ 'password' => 'string|min:6' , ] ) ; $ user -> password = bcrypt ( $ request -> input ( 'password' ) ) ; } $ user -> save ( ) ; return redirect ( ) -> route ( 'admin.home' ) -> with ( 'status' , 'User updated!' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
//Session::flash('flash_message', 'Update user successfully!');