From e72c5ccf8ab27fd836f3c476027baec3946cc3ba Mon Sep 17 00:00:00 2001 From: Samuel Date: Fri, 14 Mar 2025 18:22:16 +0100 Subject: [PATCH 1/2] Explain redirectUsersTo functionality --- authentication.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/authentication.md b/authentication.md index a06f281b202..183756b9b78 100644 --- a/authentication.md +++ b/authentication.md @@ -202,6 +202,22 @@ use Illuminate\Http\Request; }) ``` + +#### Redirecting Authenticated Users + +When the `guest` middleware detects an authenticated user, it will redirect the user to `dashboard` or `home` named route. You may modify this behavior using the method `redirectUsersTo` of your application's `bootstrap/app.php` file: + +```php +use Illuminate\Http\Request; + +->withMiddleware(function (Middleware $middleware) { + $middleware->redirectUsersTo('/panel'); + + // Using a closure... + $middleware->redirectUsersTo(fn (Request $request) => route('panel')); +}) +``` + #### Specifying a Guard From 3ad6427c02af35d839a60e4c5c8cf19d9393e17e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 17 Mar 2025 15:47:39 -0500 Subject: [PATCH 2/2] formatting --- authentication.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/authentication.md b/authentication.md index 183756b9b78..c3ce509df93 100644 --- a/authentication.md +++ b/authentication.md @@ -189,7 +189,7 @@ Route::get('/flights', function () { #### Redirecting Unauthenticated Users -When the `auth` middleware detects an unauthenticated user, it will redirect the user to the `login` [named route](/docs/{{version}}/routing#named-routes). You may modify this behavior using the method `redirectGuestsTo` of your application's `bootstrap/app.php` file: +When the `auth` middleware detects an unauthenticated user, it will redirect the user to the `login` [named route](/docs/{{version}}/routing#named-routes). You may modify this behavior using the `redirectGuestsTo` method within your application's `bootstrap/app.php` file: ```php use Illuminate\Http\Request; @@ -205,7 +205,7 @@ use Illuminate\Http\Request; #### Redirecting Authenticated Users -When the `guest` middleware detects an authenticated user, it will redirect the user to `dashboard` or `home` named route. You may modify this behavior using the method `redirectUsersTo` of your application's `bootstrap/app.php` file: +When the `guest` middleware detects an authenticated user, it will redirect the user to the `dashboard` or `home` named route. You may modify this behavior using the `redirectUsersTo` method within your application's `bootstrap/app.php` file: ```php use Illuminate\Http\Request;