Skip to content

Instantly share code, notes, and snippets.

@nulpatrol
Created October 12, 2017 10:40
Show Gist options
  • Save nulpatrol/7db75c3f8bed0a539e9f75d4be682b6f to your computer and use it in GitHub Desktop.
Save nulpatrol/7db75c3f8bed0a539e9f75d4be682b6f 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