Skip to content

Commit

Permalink
[1.x] Allow redirect()->intended() responses to be resolved via the…
Browse files Browse the repository at this point in the history
… 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]>
  • Loading branch information
crynobone and StyleCIBot authored Jul 4, 2024
1 parent ce38a4d commit 3eaf01e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/EmailVerificationPromptController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
}
}
31 changes: 31 additions & 0 deletions src/Http/Responses/RedirectAsIntended.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Laravel\Fortify\Http\Responses;

use Illuminate\Contracts\Support\Responsable;
use Laravel\Fortify\Fortify;

class RedirectAsIntended implements Responsable
{
/**
* Create a new class instance.
*
* @param string $name
* @return void
*/
public function __construct(public string $name)
{
//
}

/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function toResponse($request)
{
return redirect()->intended(Fortify::redirects($this->name));
}
}

0 comments on commit 3eaf01e

Please sign in to comment.