{"id":210,"date":"2025-08-27T13:07:13","date_gmt":"2025-08-27T13:07:13","guid":{"rendered":"https:\/\/1v0.net\/blog\/?p=210"},"modified":"2025-08-27T14:03:42","modified_gmt":"2025-08-27T14:03:42","slug":"laravel-authentication-how-to-redirect-users-after-login-logout","status":"publish","type":"post","link":"https:\/\/1v0.net\/blog\/laravel-authentication-how-to-redirect-users-after-login-logout\/","title":{"rendered":"Laravel Authentication: How to Redirect Users After Login &amp; Logout"},"content":{"rendered":"\n<p>After setting up authentication, one of the most common requirements is controlling <strong>where users are redirected<\/strong> after they log in or log out. By default, Laravel redirects users to <code>\/home<\/code> after login and back to <code>\/<\/code> after logout. But in real applications, you\u2019ll often want more control \u2014 such as sending admins to a dashboard, regular users to their profile page, or guests back to a landing page.<\/p>\n\n\n\n<p>In this guide, we\u2019ll explore <strong>how to customize Laravel 12 authentication redirects<\/strong>. We\u2019ll cover login redirects, logout redirects, role-based redirection, and even protecting against infinite redirect loops. You\u2019ll see code samples and explanations to ensure you can implement this feature confidently.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>1 &#8211; The Default Redirect (Login)<\/strong><\/h2>\n\n\n\n<p>Laravel uses the <code>RedirectsUsers<\/code> trait inside the built-in <code>LoginController<\/code> to decide where to send users after login. By default, it points to <code>\/home<\/code>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/\/ app\/Http\/Controllers\/Auth\/LoginController.php<\/span>\n\n<span class=\"hljs-keyword\">protected<\/span> $redirectTo = <span class=\"hljs-string\">'\/home'<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>You can change this to any route or path, for example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">protected<\/span> $redirectTo = <span class=\"hljs-string\">'\/dashboard'<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This is the simplest way to control post-login redirection globally for all users.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2 &#8211; Dynamic Redirects (Role-Based or Conditional)<\/strong><\/h2>\n\n\n\n<p>Often, different users should land on different pages depending on their role. Instead of a static <code>$redirectTo<\/code>, you can override the <code>redirectTo()<\/code> method:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/\/ app\/Http\/Controllers\/Auth\/LoginController.php<\/span>\n\n<span class=\"hljs-keyword\">protected<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">redirectTo<\/span><span class=\"hljs-params\">()<\/span>\n<\/span>{\n    <span class=\"hljs-keyword\">if<\/span> (auth()-&gt;user()-&gt;hasRole(<span class=\"hljs-string\">'admin'<\/span>)) {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-string\">'\/admin\/dashboard'<\/span>;\n    }\n\n    <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-string\">'\/user\/profile'<\/span>;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Here, admins are redirected to an admin dashboard, while regular users land on their profile page. You can customize this based on roles, permissions, or even subscription status.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>3 &#8211; Redirecting After Logout<\/strong><\/h2>\n\n\n\n<p>By default, Laravel redirects to <code>\/<\/code> after logout. To change this, you can override the <code>loggedOut<\/code> method in the <code>LoginController<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/\/ app\/Http\/Controllers\/Auth\/LoginController.php<\/span>\n\n<span class=\"hljs-keyword\">protected<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">loggedOut<\/span><span class=\"hljs-params\">(Request $request)<\/span>\n<\/span>{\n    <span class=\"hljs-keyword\">return<\/span> redirect(<span class=\"hljs-string\">'\/goodbye'<\/span>);\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This example sends users to a <code>\/goodbye<\/code> page after logout. You can point this to a landing page, marketing page, or even a \u201clogged out successfully\u201d message.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>4 &#8211; Redirecting Intended Users<\/strong><\/h2>\n\n\n\n<p>Laravel includes a built-in \u201cintended\u201d feature that remembers where a guest tried to go before being redirected to the login page. After login, they\u2019ll automatically go back there unless you override it. Example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/\/ app\/Http\/Controllers\/Auth\/LoginController.php<\/span>\n\n<span class=\"hljs-keyword\">protected<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">authenticated<\/span><span class=\"hljs-params\">(Request $request, $user)<\/span>\n<\/span>{\n    <span class=\"hljs-keyword\">return<\/span> redirect()-&gt;intended(<span class=\"hljs-string\">'\/dashboard'<\/span>);\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>If no intended page exists, users will land on <code>\/dashboard<\/code> instead. This ensures seamless UX \u2014 especially when protecting routes with <code>auth<\/code> middleware.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>5 &#8211; Protecting Against Redirect Loops<\/strong><\/h2>\n\n\n\n<p>Be careful not to redirect users to a route that itself requires authentication. For example, if you redirect logged-out users back to <code>\/dashboard<\/code>, they\u2019ll just hit the login screen again in a loop.<\/p>\n\n\n\n<p>Always ensure your logout redirect points to a public page, like <code>\/<\/code>, <code>\/goodbye<\/code>, or <code>\/thanks<\/code>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>You now know how to <strong>customize Laravel 12 authentication redirects<\/strong> for both login and logout. We saw how to set a global redirect, create dynamic role-based redirects, override logout behavior, and use Laravel\u2019s intended feature for smarter flows. With these techniques, you can tailor the authentication flow to match your app\u2019s UX perfectly.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\">What\u2019s Next<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"\/blog\/how-to-restrict-page-access-by-role-in-laravel-12\">How to Restrict Page Access by Role in Laravel 12<\/a> \u2014 redirect users away from pages they can\u2019t access.<\/li>\n<li><a href=\"\/blog\/implementing-passwordless-authentication-in-laravel-12\">Implementing Passwordless Authentication in Laravel 12<\/a> \u2014 modernize login UX even further.<\/li>\n<li><a href=\"\/blog\/implementing-two-factor-authentication-in-laravel\">Implementing Two-Factor Authentication in Laravel<\/a> \u2014 add stronger login security.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>After setting up authentication, one of the most common requirements is controlling where users are redirected after they log in or log out. By default, Laravel redirects users to \/home after login and back to \/ after logout. But in real applications, you\u2019ll often want more control \u2014 such as sending admins to a dashboard, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":235,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[12,13],"class_list":["post-210","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-authentication","tag-login"],"_links":{"self":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts\/210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/comments?post=210"}],"version-history":[{"count":1,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts\/210\/revisions"}],"predecessor-version":[{"id":213,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts\/210\/revisions\/213"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/media\/235"}],"wp:attachment":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/media?parent=210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/categories?post=210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/tags?post=210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}