PasswordResetLinkController.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Http\JsonResponse;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Password;
  7. use Illuminate\Validation\ValidationException;
  8. class PasswordResetLinkController extends Controller
  9. {
  10. /**
  11. * Handle an incoming password reset link request.
  12. *
  13. * @throws \Illuminate\Validation\ValidationException
  14. */
  15. public function store(Request $request): JsonResponse
  16. {
  17. $request->validate([
  18. 'email' => ['required', 'email'],
  19. ]);
  20. // We will send the password reset link to this user. Once we have attempted
  21. // to send the link, we will examine the response then see the message we
  22. // need to show to the user. Finally, we'll send out a proper response.
  23. $status = Password::sendResetLink(
  24. $request->only('email')
  25. );
  26. if ($status != Password::RESET_LINK_SENT) {
  27. throw ValidationException::withMessages([
  28. 'email' => [__($status)],
  29. ]);
  30. }
  31. return response()->json(['status' => __($status)]);
  32. }
  33. }