app/Http/Controllers/Dashboard/Users.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( User $user , Request $request)
    {
        $requestArray = request()->validate([
            'name'  => ['required' , 'string'],
            'email' => ['required' , 'email'],
            'group' => ['required' , 'string']
        ]);
        if ($request->has('password') && $request->get('password') != "") {
            $requestArray = 
            $requestArray + [ 'password' => Hash::make($request->password)];
        }
        $user->update($requestArray);
        alert()->success('User Updated' , 'Done');
        return redirect()->route('users.index');
    }
public function update ( User $ user , Request $ request ) { $ requestArray = request ( ) -> validate ( [ 'name' => [ 'required' , 'string' ] , 'email' => [ 'required' , 'email' ] , 'group' => [ 'required' , 'string' ] ] ) ; if ( $ request -> has ( 'password' ) && $ request -> get ( 'password' ) != " " ) { $ requestArray = $ requestArray + [ 'password' => Hash :: make ( $ request -> password ) ] ; } $ user -> update ( $ requestArray ) ; alert ( ) -> success ( 'User Updated' , 'Done' ) ; return redirect ( ) -> route ( 'users.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
// dd($request); // This is to ensure that the password will stay the same if the user didnt     // enter any password // i can use request() helper function since it equals $request->input() opject  // dd($requestArray);