app/Http/Controllers/UserController.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)
    {
        $this->validate($request, [
            'name' => 'required',
            'email' => 'required|email|unique:users,email,'.$id,
            'password' => 'confirmed',
            'roles' => 'required'
        ]);
        $input = $request->all();
        if(!empty($input['password'])) { 
            $input['password'] = FacadesHash::make($input['password']);
        } else {
            $input = Arr::except($input, array('password'));    
        }
        $user = User::find($id);
        $user->update($input);
        FacadesDB::table('model_has_roles')
            ->where('model_id', $id)
            ->delete();
        $user->assignRole($request->input('roles'));
        return redirect()->route('users.index')
            ->with('success', 'User updated successfully.');
    }
public function update ( Request $ request , $ id ) { $ this -> validate ( $ request , [ 'name' => 'required' , 'email' => 'required|email|unique:users,email,' . $ id , 'password' => 'confirmed' , 'roles' => 'required' ] ) ; $ input = $ request -> all ( ) ; if ( ! empty ( $ input [ 'password' ] ) ) { $ input [ 'password' ] = FacadesHash :: make ( $ input [ 'password' ] ) ; } else { $ input = Arr :: except ( $ input , array ( 'password' ) ) ; } $ user = User :: find ( $ id ) ; $ user -> update ( $ input ) ; FacadesDB :: table ( 'model_has_roles' ) -> where ( 'model_id' , $ id ) -> delete ( ) ; $ user -> assignRole ( $ request -> input ( 'roles' ) ) ; return redirect ( ) -> route ( 'users.index' ) -> with ( 'success' , 'User updated successfully.' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .