Skip to content

Instantly share code, notes, and snippets.

@nulpatrol
Created October 19, 2017 07:56
Show Gist options
  • Save nulpatrol/04943694c31494fb7ed3ff3ec6a1a1d9 to your computer and use it in GitHub Desktop.
Save nulpatrol/04943694c31494fb7ed3ff3ec6a1a1d9 to your computer and use it in GitHub Desktop.
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