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