Replies: 1 comment 4 replies
-
You can configure it at ->withMiddleware(function (Middleware $middleware) {
$middleware->redirectUsersTo(function(Request $request) {
return $request->user()->isAdmin() ? '/admin' : '/home';
});
}) |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
I'm currently working on creating website using Laravel 11 with scaffolding using Breeze. I had some issues related to middleware that included in laravel and used on route generated by Breeze.
I have my routes.php looks like this:
Had some changes on AuthenticatedSessionController::class only to check if user's role for redirecting to spesific route
After successfully attempting to login and had some error because I haven't implemented route for 'user.dashboard' and 'admin.dashboard' then refresh the page, it redirect me to path '/' which I don't remember to redirect there when user authenticated. When I tried to access path 'auth/login' it redirects me to '/' because I assume the user already logged in and 'guest' middleware tries to redirect me to default path when user is authenticated.
So I tried to retrace my step when creating the login feature, and found that when removing 'guest' middleware make the feature work as intended and not redirecting me to '/' again.
And I remember how to change this behaviour when using Laravel 10 before to change route to home page or something inside middleware RedirectIfAuthenticated.php which is part of 'guest' middleware, but in Laravel 11, this file is moved inside the framework itself which it surely cannot be modified directly.
I haven't found a reference how to solve this, so might be someone might had found its solution would be appreciated sharing it here.
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions