app/Http/Controllers/Admin/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)
    {
        $dados = $request->all();
        if(isset($dados['password']) && $dados['password'] != ""){
            $validacao = Validator::make($dados, [
                'name' => 'required|string|max:255',
                'email' => [
                    'required','string','email','max:255',
                    Rule::unique('users')->ignore($id)
                ],
                'password' => 'required|string|min:6|',
            ]);
            $dados['password'] = Hash::make($dados['password']);
        }else{
            $validacao = Validator::make($dados, [
                'name' => 'required|string|max:255',
                'email' => [
                    'required','string','email','max:255',
                    Rule::unique('users')->ignore($id)
                ],
            ]);
            unset($dados["password"]);
        }
        if($validacao->fails()){
            return redirect()
                ->back()
                ->withErrors($validacao)
                ->withInput();
        }
        User::find($id)->update($dados);
        return redirect()->back();
    }
public function update ( Request $ request , $ id ) { $ dados = $ request -> all ( ) ; if ( isset ( $ dados [ 'password' ] ) && $ dados [ 'password' ] != " " ) { $ validacao = Validator :: make ( $ dados , [ 'name' => 'required|string|max:255' , 'email' => [ 'required' , 'string' , 'email' , 'max:255' , Rule :: unique ( 'users' ) -> ignore ( $ id ) ] , 'password' => 'required|string|min:6|' , ] ) ; $ dados [ 'password' ] = Hash :: make ( $ dados [ 'password' ] ) ; } else { $ validacao = Validator :: make ( $ dados , [ 'name' => 'required|string|max:255' , 'email' => [ 'required' , 'string' , 'email' , 'max:255' , Rule :: unique ( 'users' ) -> ignore ( $ id ) ] , ] ) ; unset ( $ dados [ " password " ] ) ; } if ( $ validacao -> fails ( ) ) { return redirect ( ) -> back ( ) -> withErrors ( $ validacao ) -> withInput ( ) ; } User :: find ( $ id ) -> update ( $ dados ) ; return redirect ( ) -> back ( ) ; }
Update the specified resource in storage.
Update the specified resource in storage .