app/Http/Controllers/Admin/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)
    {
        if($request->get('changepassword')){
            $user =  User::find($id); 
            if (!Hash::check($request->get('oldpassword'), $user->password)){
                return redirect()->back()->with('error', "Current Password not matched.");
            }
            $validator = Validator::make($request->all(), [
                'password' => 'required|confirmed|min:6'
            ]);
            if ($validator->fails()) {
                return redirect('/changepassword/')
                            ->withErrors($validator)
                            ->withInput();
            }
            $user->password=Hash::make($request->get('password'));
            $date=date_create($request->get('date'));
            $format = date_format($date,"Y-m-d");
            $user->updated_at = strtotime($format);
            $user->save();
            return redirect()->back()->with('success', "Your Password has been changed.");
        }elseif($request->get('resetpassword')){
            $this->authorize('edit-staff');
            $user =  User::find($id); 
            $validator = Validator::make($request->all(), [
                'password' => 'required|confirmed|min:6'
            ]);
            if ($validator->fails()) {
                return redirect('/resetpassword/'.$id)
                            ->withErrors($validator)
                            ->withInput();
            }
            $user->password=Hash::make($request->get('password'));
            $date=date_create($request->get('date'));
            $format = date_format($date,"Y-m-d");
            $user->updated_at = strtotime($format);
            $user->save();
            return redirect()->action(
                'Admin\UserController@resetPassword', ['id' => $user->id]
            )->with('success', 'Password has been reset.');
        }else{
            $this->authorize('edit-staff');
            if($request->hasfile('avatar-1'))
            {
                $file = $request->file('avatar-1');
                $avatarname=time().$file->getClientOriginalName();
                $file->move(public_path().'/img/staff', $avatarname);
            }
            $user = User::find($id); 
            $this->validate(request(), [
                'fname' => 'required',
                'lname' => 'required',
                'email' => 'required|email|unique:users,email,'.$user->id,
                'phonenumber' => 'required'
            ]);
            $user->fname=$request->get('fname');
            $user->lname=$request->get('lname');
            $user->email=$request->get('email');
            if(!empty($request->get('role_id'))){
                $user->role_id=$request->get('role_id');
            }
            $user->phonenumber=$request->get('phonenumber');
            if(!$request->get('profile')){
            $user->status=$request->get('status');
            }
            $date=date_create($request->get('date'));
            $format = date_format($date,"Y-m-d");
            $user->updated_at = strtotime($format);
            if(isset($avatarname)){
                $user->avatar = $avatarname;
            }
            $user->save();
            if($request->get('profile')){
                $message='Profile details has been updated.';
            }else{
                $message='Staff details has been updated';
            }
            return redirect()->back()->with('success', $message);
        }
    }
public function update ( Request $ request , $ id ) { if ( $ request -> get ( 'changepassword' ) ) { $ user = User :: find ( $ id ) ; if ( ! Hash :: check ( $ request -> get ( 'oldpassword' ) , $ user -> password ) ) { return redirect ( ) -> back ( ) -> with ( 'error' , " Current Password not matched. " ) ; } $ validator = Validator :: make ( $ request -> all ( ) , [ 'password' => 'required|confirmed|min:6' ] ) ; if ( $ validator -> fails ( ) ) { return redirect ( '/changepassword/' ) -> withErrors ( $ validator ) -> withInput ( ) ; } $ user -> password = Hash :: make ( $ request -> get ( 'password' ) ) ; $ date = date_create ( $ request -> get ( 'date' ) ) ; $ format = date_format ( $ date , " Y-m-d " ) ; $ user -> updated_at = strtotime ( $ format ) ; $ user -> save ( ) ; return redirect ( ) -> back ( ) -> with ( 'success' , " Your Password has been changed. " ) ; } elseif ( $ request -> get ( 'resetpassword' ) ) { $ this -> authorize ( 'edit-staff' ) ; $ user = User :: find ( $ id ) ; $ validator = Validator :: make ( $ request -> all ( ) , [ 'password' => 'required|confirmed|min:6' ] ) ; if ( $ validator -> fails ( ) ) { return redirect ( '/resetpassword/' . $ id ) -> withErrors ( $ validator ) -> withInput ( ) ; } $ user -> password = Hash :: make ( $ request -> get ( 'password' ) ) ; $ date = date_create ( $ request -> get ( 'date' ) ) ; $ format = date_format ( $ date , " Y-m-d " ) ; $ user -> updated_at = strtotime ( $ format ) ; $ user -> save ( ) ; return redirect ( ) -> action ( 'Admin\UserController@resetPassword' , [ 'id' => $ user -> id ] ) -> with ( 'success' , 'Password has been reset.' ) ; } else { $ this -> authorize ( 'edit-staff' ) ; if ( $ request -> hasfile ( 'avatar-1' ) ) { $ file = $ request -> file ( 'avatar-1' ) ; $ avatarname = time ( ) . $ file -> getClientOriginalName ( ) ; $ file -> move ( public_path ( ) . '/img/staff' , $ avatarname ) ; } $ user = User :: find ( $ id ) ; $ this -> validate ( request ( ) , [ 'fname' => 'required' , 'lname' => 'required' , 'email' => 'required|email|unique:users,email,' . $ user -> id , 'phonenumber' => 'required' ] ) ; $ user -> fname = $ request -> get ( 'fname' ) ; $ user -> lname = $ request -> get ( 'lname' ) ; $ user -> email = $ request -> get ( 'email' ) ; if ( ! empty ( $ request -> get ( 'role_id' ) ) ) { $ user -> role_id = $ request -> get ( 'role_id' ) ; } $ user -> phonenumber = $ request -> get ( 'phonenumber' ) ; if ( ! $ request -> get ( 'profile' ) ) { $ user -> status = $ request -> get ( 'status' ) ; } $ date = date_create ( $ request -> get ( 'date' ) ) ; $ format = date_format ( $ date , " Y-m-d " ) ; $ user -> updated_at = strtotime ( $ format ) ; if ( isset ( $ avatarname ) ) { $ user -> avatar = $ avatarname ; } $ user -> save ( ) ; if ( $ request -> get ( 'profile' ) ) { $ message = 'Profile details has been updated.' ; } else { $ message = 'Staff details has been updated' ; } return redirect ( ) -> back ( ) -> with ( 'success' , $ message ) ; } }
Update the specified resource in storage.
Update the specified resource in storage .
//Change Password //Check The Current Password Matched //Reset Password //Update Staff/User details // dd($request->file('avatar-1')); // dd($avatarname);