Created
          October 12, 2017 10:40 
        
      - 
      
- 
        Save nulpatrol/7db75c3f8bed0a539e9f75d4be682b6f to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | public function changePassword() | |
| { | |
| try { | |
| $user = User::findOrFail(request()->input('id')); | |
| if (Hash::check(request()->input('password'), $user->password)) { | |
| throw ValidationException::withMessages([ | |
| 'password' => ['translation.newPasswordMustBeDifferent'] | |
| ]); | |
| } | |
| request()->validate([ | |
| 'password' => 'required|string|min:6', | |
| ]); | |
| $user->password = bcrypt(request()->input('password')); | |
| $user->save(); | |
| return response()->json([ | |
| 'status' => 1, | |
| 'message' => 'success', | |
| ]); | |
| } catch (ValidationException $ex) { | |
| return response()->json([ | |
| 'status' => 0, | |
| 'message' => 'error', | |
| 'error' => $ex->errors(), | |
| ], 422); | |
| } catch (\Exception $ex) { | |
| return response()->json([ | |
| 'status' => 0, | |
| 'message' => 'error', | |
| 'error' => $ex->getMessage(), | |
| ], 500); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment