Skip to content

Commit 3eaf01e

Browse files
[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 <[email protected]> * Apply fixes from StyleCI * Apply suggestions from code review --------- Signed-off-by: Mior Muhammad Zaki <[email protected]> Co-authored-by: StyleCI Bot <[email protected]>
1 parent ce38a4d commit 3eaf01e

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

src/Http/Controllers/EmailVerificationNotificationController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Illuminate\Http\Request;
77
use Illuminate\Routing\Controller;
88
use Laravel\Fortify\Contracts\EmailVerificationNotificationSentResponse;
9-
use Laravel\Fortify\Fortify;
9+
use Laravel\Fortify\Http\Responses\RedirectAsIntended;
1010

1111
class EmailVerificationNotificationController extends Controller
1212
{
@@ -21,7 +21,7 @@ public function store(Request $request)
2121
if ($request->user()->hasVerifiedEmail()) {
2222
return $request->wantsJson()
2323
? new JsonResponse('', 204)
24-
: redirect()->intended(Fortify::redirects('email-verification'));
24+
: app(RedirectAsIntended::class, ['name' => 'email-verification']);
2525
}
2626

2727
$request->user()->sendEmailVerificationNotification();

src/Http/Controllers/EmailVerificationPromptController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Illuminate\Http\Request;
66
use Illuminate\Routing\Controller;
77
use Laravel\Fortify\Contracts\VerifyEmailViewResponse;
8-
use Laravel\Fortify\Fortify;
8+
use Laravel\Fortify\Http\Responses\RedirectAsIntended;
99

1010
class EmailVerificationPromptController extends Controller
1111
{
@@ -18,7 +18,7 @@ class EmailVerificationPromptController extends Controller
1818
public function __invoke(Request $request)
1919
{
2020
return $request->user()->hasVerifiedEmail()
21-
? redirect()->intended(Fortify::redirects('email-verification'))
21+
? app(RedirectAsIntended::class, ['name' => 'email-verification'])
2222
: app(VerifyEmailViewResponse::class);
2323
}
2424
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Laravel\Fortify\Http\Responses;
4+
5+
use Illuminate\Contracts\Support\Responsable;
6+
use Laravel\Fortify\Fortify;
7+
8+
class RedirectAsIntended implements Responsable
9+
{
10+
/**
11+
* Create a new class instance.
12+
*
13+
* @param string $name
14+
* @return void
15+
*/
16+
public function __construct(public string $name)
17+
{
18+
//
19+
}
20+
21+
/**
22+
* Create an HTTP response that represents the object.
23+
*
24+
* @param \Illuminate\Http\Request $request
25+
* @return \Symfony\Component\HttpFoundation\Response
26+
*/
27+
public function toResponse($request)
28+
{
29+
return redirect()->intended(Fortify::redirects($this->name));
30+
}
31+
}

0 commit comments

Comments
 (0)