From 3eaf01ec826c4f653628202640a4450784f78b15 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 4 Jul 2024 22:36:27 +0800 Subject: [PATCH] [1.x] Allow `redirect()->intended()` responses to be resolved via the Container (#551) * Allow `PasswordBroker` and `redirect()->intended()` responses to be resolved via the Container Signed-off-by: Mior Muhammad Zaki * Apply fixes from StyleCI * Apply suggestions from code review --------- Signed-off-by: Mior Muhammad Zaki Co-authored-by: StyleCI Bot --- ...mailVerificationNotificationController.php | 4 +-- .../EmailVerificationPromptController.php | 4 +-- src/Http/Responses/RedirectAsIntended.php | 31 +++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 src/Http/Responses/RedirectAsIntended.php diff --git a/src/Http/Controllers/EmailVerificationNotificationController.php b/src/Http/Controllers/EmailVerificationNotificationController.php index 3a270920..05196b30 100644 --- a/src/Http/Controllers/EmailVerificationNotificationController.php +++ b/src/Http/Controllers/EmailVerificationNotificationController.php @@ -6,7 +6,7 @@ use Illuminate\Http\Request; use Illuminate\Routing\Controller; use Laravel\Fortify\Contracts\EmailVerificationNotificationSentResponse; -use Laravel\Fortify\Fortify; +use Laravel\Fortify\Http\Responses\RedirectAsIntended; class EmailVerificationNotificationController extends Controller { @@ -21,7 +21,7 @@ public function store(Request $request) if ($request->user()->hasVerifiedEmail()) { return $request->wantsJson() ? new JsonResponse('', 204) - : redirect()->intended(Fortify::redirects('email-verification')); + : app(RedirectAsIntended::class, ['name' => 'email-verification']); } $request->user()->sendEmailVerificationNotification(); diff --git a/src/Http/Controllers/EmailVerificationPromptController.php b/src/Http/Controllers/EmailVerificationPromptController.php index 40f0e761..c09a9b30 100644 --- a/src/Http/Controllers/EmailVerificationPromptController.php +++ b/src/Http/Controllers/EmailVerificationPromptController.php @@ -5,7 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Routing\Controller; use Laravel\Fortify\Contracts\VerifyEmailViewResponse; -use Laravel\Fortify\Fortify; +use Laravel\Fortify\Http\Responses\RedirectAsIntended; class EmailVerificationPromptController extends Controller { @@ -18,7 +18,7 @@ class EmailVerificationPromptController extends Controller public function __invoke(Request $request) { return $request->user()->hasVerifiedEmail() - ? redirect()->intended(Fortify::redirects('email-verification')) + ? app(RedirectAsIntended::class, ['name' => 'email-verification']) : app(VerifyEmailViewResponse::class); } } diff --git a/src/Http/Responses/RedirectAsIntended.php b/src/Http/Responses/RedirectAsIntended.php new file mode 100644 index 00000000..8d79642a --- /dev/null +++ b/src/Http/Responses/RedirectAsIntended.php @@ -0,0 +1,31 @@ +intended(Fortify::redirects($this->name)); + } +}