{"id":126,"date":"2025-08-25T16:13:38","date_gmt":"2025-08-25T16:13:38","guid":{"rendered":"https:\/\/1v0.net\/blog\/?p=126"},"modified":"2025-08-26T08:49:57","modified_gmt":"2025-08-26T08:49:57","slug":"how-to-add-authentication-in-laravel-12-without-fortify","status":"publish","type":"post","link":"https:\/\/1v0.net\/blog\/how-to-add-authentication-in-laravel-12-without-fortify\/","title":{"rendered":"How to Add Authentication in Laravel 12 (Without Fortify)"},"content":{"rendered":"\n<p>Authentication is one of the first features developers add to a new Laravel project. While Laravel Fortify provides a robust solution, sometimes you want to implement basic login, registration, and logout yourself to keep things simple or learn how it works under the hood.<\/p>\n\n\n\n<p>In this guide, we\u2019ll build a lightweight authentication system in Laravel 12 without using Fortify. You\u2019ll see how to create routes, controllers, and views for user login and registration, as well as handle session-based authentication with Laravel\u2019s built-in features.<\/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<h2 class=\"wp-block-heading\"><strong>1 &#8211; Setup Database and User Model<\/strong><\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>Make sure your <code>.env<\/code> file has database credentials set up and run the default Laravel migration. This will create the <code>users<\/code> table.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">php artisan migrate<\/code><\/span><\/pre>\n\n\n<p>The default <code>User<\/code> model is already included in <code>app\/Models\/User.php<\/code> and comes with fields like <code>name<\/code>, <code>email<\/code>, and <code>password<\/code> which are enough for our basic authentication system.<\/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<h2 class=\"wp-block-heading\"><strong>2 &#8211; Define Authentication Routes<\/strong><\/h2>\n\n\n\n<p><\/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 shcb-code-table shcb-line-numbers shcb-wrap-lines\"><span class='shcb-loc'><span><span class=\"hljs-comment\">\/\/ routes\/web.php<\/span>\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">App<\/span>\\<span class=\"hljs-title\">Http<\/span>\\<span class=\"hljs-title\">Controllers<\/span>\\<span class=\"hljs-title\">AuthController<\/span>;\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">Illuminate<\/span>\\<span class=\"hljs-title\">Support<\/span>\\<span class=\"hljs-title\">Facades<\/span>\\<span class=\"hljs-title\">Route<\/span>;\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-comment\">\/\/ Guest routes<\/span>\n<\/span><\/span><span class='shcb-loc'><span>Route::middleware(<span class=\"hljs-string\">'guest'<\/span>)-&gt;group(<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-params\">()<\/span> <\/span>{\n<\/span><\/span><span class='shcb-loc'><span>    Route::get(<span class=\"hljs-string\">'\/register'<\/span>, &#91;AuthController::class, <span class=\"hljs-string\">'showRegister'<\/span>])-&gt;name(<span class=\"hljs-string\">'register.show'<\/span>);\n<\/span><\/span><span class='shcb-loc'><span>    Route::post(<span class=\"hljs-string\">'\/register'<\/span>, &#91;AuthController::class, <span class=\"hljs-string\">'register'<\/span>])-&gt;name(<span class=\"hljs-string\">'register'<\/span>);\n<\/span><\/span><span class='shcb-loc'><span>    Route::get(<span class=\"hljs-string\">'\/login'<\/span>, &#91;AuthController::class, <span class=\"hljs-string\">'showLogin'<\/span>])-&gt;name(<span class=\"hljs-string\">'login.show'<\/span>);\n<\/span><\/span><span class='shcb-loc'><span>    Route::post(<span class=\"hljs-string\">'\/login'<\/span>, &#91;AuthController::class, <span class=\"hljs-string\">'login'<\/span>])-&gt;name(<span class=\"hljs-string\">'login'<\/span>);\n<\/span><\/span><span class='shcb-loc'><span>});\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-comment\">\/\/ Authenticated routes<\/span>\n<\/span><\/span><span class='shcb-loc'><span>Route::middleware(<span class=\"hljs-string\">'auth'<\/span>)-&gt;group(<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-params\">()<\/span> <\/span>{\n<\/span><\/span><span class='shcb-loc'><span>    Route::post(<span class=\"hljs-string\">'\/logout'<\/span>, &#91;AuthController::class, <span class=\"hljs-string\">'logout'<\/span>])-&gt;name(<span class=\"hljs-string\">'logout'<\/span>);\n<\/span><\/span><span class='shcb-loc'><span>    Route::get(<span class=\"hljs-string\">'\/dashboard'<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-params\">()<\/span> <\/span>{\n<\/span><\/span><span class='shcb-loc'><span>        <span class=\"hljs-keyword\">return<\/span> view(<span class=\"hljs-string\">'dashboard'<\/span>);\n<\/span><\/span><span class='shcb-loc'><span>    })-&gt;name(<span class=\"hljs-string\">'dashboard'<\/span>);\n<\/span><\/span><span class='shcb-loc'><span>});\n<\/span><\/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>Here we define routes for registration, login, and logout. The <code>guest<\/code> middleware ensures only non-logged-in users can access login and registration. The <code>auth<\/code> middleware ensures only authenticated users can see the dashboard or logout.<\/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<h2 class=\"wp-block-heading\"><strong>3 &#8211; Build the AuthController<\/strong><\/h2>\n\n\n\n<p><\/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 shcb-code-table shcb-line-numbers shcb-wrap-lines\"><span class='shcb-loc'><span><span class=\"hljs-comment\">\/\/ app\/Http\/Controllers\/AuthController.php<\/span>\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-keyword\">namespace<\/span> <span class=\"hljs-title\">App<\/span>\\<span class=\"hljs-title\">Http<\/span>\\<span class=\"hljs-title\">Controllers<\/span>;\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">App<\/span>\\<span class=\"hljs-title\">Models<\/span>\\<span class=\"hljs-title\">User<\/span>;\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">Illuminate<\/span>\\<span class=\"hljs-title\">Http<\/span>\\<span class=\"hljs-title\">Request<\/span>;\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">Illuminate<\/span>\\<span class=\"hljs-title\">Support<\/span>\\<span class=\"hljs-title\">Facades<\/span>\\<span class=\"hljs-title\">Auth<\/span>;\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">Illuminate<\/span>\\<span class=\"hljs-title\">Support<\/span>\\<span class=\"hljs-title\">Facades<\/span>\\<span class=\"hljs-title\">Hash<\/span>;\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">AuthController<\/span> <span class=\"hljs-keyword\">extends<\/span> <span class=\"hljs-title\">Controller<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-class\"><\/span>{\n<\/span><\/span><span class='shcb-loc'><span>    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">showRegister<\/span><span class=\"hljs-params\">()<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-function\">    <\/span>{\n<\/span><\/span><span class='shcb-loc'><span>        <span class=\"hljs-keyword\">return<\/span> view(<span class=\"hljs-string\">'auth.register'<\/span>);\n<\/span><\/span><span class='shcb-loc'><span>    }\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span>    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">register<\/span><span class=\"hljs-params\">(Request $request)<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-function\">    <\/span>{\n<\/span><\/span><span class='shcb-loc'><span>        $request-&gt;validate(&#91;\n<\/span><\/span><span class='shcb-loc'><span>            <span class=\"hljs-string\">'name'<\/span> =&gt; <span class=\"hljs-string\">'required|string|max:255'<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>            <span class=\"hljs-string\">'email'<\/span> =&gt; <span class=\"hljs-string\">'required|email|unique:users'<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>            <span class=\"hljs-string\">'password'<\/span> =&gt; <span class=\"hljs-string\">'required|min:6|confirmed'<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>        ]);\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span>        $user = User::create(&#91;\n<\/span><\/span><span class='shcb-loc'><span>            <span class=\"hljs-string\">'name'<\/span> =&gt; $request-&gt;name,\n<\/span><\/span><span class='shcb-loc'><span>            <span class=\"hljs-string\">'email'<\/span> =&gt; $request-&gt;email,\n<\/span><\/span><span class='shcb-loc'><span>            <span class=\"hljs-string\">'password'<\/span> =&gt; Hash::make($request-&gt;password),\n<\/span><\/span><span class='shcb-loc'><span>        ]);\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span>        Auth::login($user);\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span>        <span class=\"hljs-keyword\">return<\/span> redirect()-&gt;route(<span class=\"hljs-string\">'dashboard'<\/span>);\n<\/span><\/span><span class='shcb-loc'><span>    }\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span>    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">showLogin<\/span><span class=\"hljs-params\">()<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-function\">    <\/span>{\n<\/span><\/span><span class='shcb-loc'><span>        <span class=\"hljs-keyword\">return<\/span> view(<span class=\"hljs-string\">'auth.login'<\/span>);\n<\/span><\/span><span class='shcb-loc'><span>    }\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span>    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">login<\/span><span class=\"hljs-params\">(Request $request)<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-function\">    <\/span>{\n<\/span><\/span><span class='shcb-loc'><span>        $credentials = $request-&gt;validate(&#91;\n<\/span><\/span><span class='shcb-loc'><span>            <span class=\"hljs-string\">'email'<\/span> =&gt; <span class=\"hljs-string\">'required|email'<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>            <span class=\"hljs-string\">'password'<\/span> =&gt; <span class=\"hljs-string\">'required'<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>        ]);\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span>        <span class=\"hljs-keyword\">if<\/span> (Auth::attempt($credentials, $request-&gt;filled(<span class=\"hljs-string\">'remember'<\/span>))) {\n<\/span><\/span><span class='shcb-loc'><span>            $request-&gt;session()-&gt;regenerate();\n<\/span><\/span><span class='shcb-loc'><span>            <span class=\"hljs-keyword\">return<\/span> redirect()-&gt;route(<span class=\"hljs-string\">'dashboard'<\/span>);\n<\/span><\/span><span class='shcb-loc'><span>        }\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span>        <span class=\"hljs-keyword\">return<\/span> back()-&gt;withErrors(&#91;\n<\/span><\/span><span class='shcb-loc'><span>            <span class=\"hljs-string\">'email'<\/span> =&gt; <span class=\"hljs-string\">'Invalid credentials provided.'<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>        ]);\n<\/span><\/span><span class='shcb-loc'><span>    }\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span>    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">logout<\/span><span class=\"hljs-params\">(Request $request)<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-function\">    <\/span>{\n<\/span><\/span><span class='shcb-loc'><span>        Auth::logout();\n<\/span><\/span><span class='shcb-loc'><span>        $request-&gt;session()-&gt;invalidate();\n<\/span><\/span><span class='shcb-loc'><span>        $request-&gt;session()-&gt;regenerateToken();\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span>        <span class=\"hljs-keyword\">return<\/span> redirect()-&gt;route(<span class=\"hljs-string\">'login.show'<\/span>);\n<\/span><\/span><span class='shcb-loc'><span>    }\n<\/span><\/span><span class='shcb-loc'><span>}\n<\/span><\/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 controller handles showing login\/register forms, creating new users, authenticating credentials, and logging users out. Laravel\u2019s <code>Auth<\/code> facade is used to manage sessions securely.<\/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<h2 class=\"wp-block-heading\"><strong>4 &#8211; Create Blade Views<\/strong><\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>We\u2019ll need three simple Blade templates: one for registration, one for login, and one for the dashboard.<\/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\">\/\/ resources\/views\/auth\/register.blade.php<\/span>\n\n&lt;form method=<span class=\"hljs-string\">\"POST\"<\/span> action=<span class=\"hljs-string\">\"{{ route('register') }}\"<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span>=\"<span class=\"hljs-title\">card<\/span> <span class=\"hljs-title\">card<\/span>-<span class=\"hljs-title\">body<\/span>\"&gt;\n    @<span class=\"hljs-title\">csrf<\/span>\n    &lt;<span class=\"hljs-title\">h2<\/span>&gt;<span class=\"hljs-title\">Register<\/span>&lt;\/<span class=\"hljs-title\">h2<\/span>&gt;\n    &lt;<span class=\"hljs-title\">input<\/span> <span class=\"hljs-title\">type<\/span>=\"<span class=\"hljs-title\">text<\/span>\" <span class=\"hljs-title\">name<\/span>=\"<span class=\"hljs-title\">name<\/span>\" <span class=\"hljs-title\">placeholder<\/span>=\"<span class=\"hljs-title\">Name<\/span>\" <span class=\"hljs-title\">required<\/span> <span class=\"hljs-title\">class<\/span>=\"<span class=\"hljs-title\">form<\/span>-<span class=\"hljs-title\">control<\/span> <span class=\"hljs-title\">mb<\/span>-2\"&gt;\n    &lt;<span class=\"hljs-title\">input<\/span> <span class=\"hljs-title\">type<\/span>=\"<span class=\"hljs-title\">email<\/span>\" <span class=\"hljs-title\">name<\/span>=\"<span class=\"hljs-title\">email<\/span>\" <span class=\"hljs-title\">placeholder<\/span>=\"<span class=\"hljs-title\">Email<\/span>\" <span class=\"hljs-title\">required<\/span> <span class=\"hljs-title\">class<\/span>=\"<span class=\"hljs-title\">form<\/span>-<span class=\"hljs-title\">control<\/span> <span class=\"hljs-title\">mb<\/span>-2\"&gt;\n    &lt;<span class=\"hljs-title\">input<\/span> <span class=\"hljs-title\">type<\/span>=\"<span class=\"hljs-title\">password<\/span>\" <span class=\"hljs-title\">name<\/span>=\"<span class=\"hljs-title\">password<\/span>\" <span class=\"hljs-title\">placeholder<\/span>=\"<span class=\"hljs-title\">Password<\/span>\" <span class=\"hljs-title\">required<\/span> <span class=\"hljs-title\">class<\/span>=\"<span class=\"hljs-title\">form<\/span>-<span class=\"hljs-title\">control<\/span> <span class=\"hljs-title\">mb<\/span>-2\"&gt;\n    &lt;<span class=\"hljs-title\">input<\/span> <span class=\"hljs-title\">type<\/span>=\"<span class=\"hljs-title\">password<\/span>\" <span class=\"hljs-title\">name<\/span>=\"<span class=\"hljs-title\">password_confirmation<\/span>\" <span class=\"hljs-title\">placeholder<\/span>=\"<span class=\"hljs-title\">Confirm<\/span> <span class=\"hljs-title\">Password<\/span>\" <span class=\"hljs-title\">required<\/span> <span class=\"hljs-title\">class<\/span>=\"<span class=\"hljs-title\">form<\/span>-<span class=\"hljs-title\">control<\/span> <span class=\"hljs-title\">mb<\/span>-2\"&gt;\n    &lt;<span class=\"hljs-title\">button<\/span> <span class=\"hljs-title\">class<\/span>=\"<span class=\"hljs-title\">btn<\/span> <span class=\"hljs-title\">btn<\/span>-<span class=\"hljs-title\">primary<\/span>\"&gt;<span class=\"hljs-title\">Register<\/span>&lt;\/<span class=\"hljs-title\">button<\/span>&gt;\n&lt;\/<span class=\"hljs-title\">form<\/span>&gt;<\/span><\/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>The registration form collects user details and submits them to the <code>register<\/code> route. Laravel automatically handles CSRF protection with the <code>@csrf<\/code> directive.<\/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\">\/\/ resources\/views\/auth\/login.blade.php<\/span>\n\n&lt;form method=<span class=\"hljs-string\">\"POST\"<\/span> action=<span class=\"hljs-string\">\"{{ route('login') }}\"<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span>=\"<span class=\"hljs-title\">card<\/span> <span class=\"hljs-title\">card<\/span>-<span class=\"hljs-title\">body<\/span>\"&gt;\n    @<span class=\"hljs-title\">csrf<\/span>\n    &lt;<span class=\"hljs-title\">h2<\/span>&gt;<span class=\"hljs-title\">Login<\/span>&lt;\/<span class=\"hljs-title\">h2<\/span>&gt;\n    &lt;<span class=\"hljs-title\">input<\/span> <span class=\"hljs-title\">type<\/span>=\"<span class=\"hljs-title\">email<\/span>\" <span class=\"hljs-title\">name<\/span>=\"<span class=\"hljs-title\">email<\/span>\" <span class=\"hljs-title\">placeholder<\/span>=\"<span class=\"hljs-title\">Email<\/span>\" <span class=\"hljs-title\">required<\/span> <span class=\"hljs-title\">class<\/span>=\"<span class=\"hljs-title\">form<\/span>-<span class=\"hljs-title\">control<\/span> <span class=\"hljs-title\">mb<\/span>-2\"&gt;\n    &lt;<span class=\"hljs-title\">input<\/span> <span class=\"hljs-title\">type<\/span>=\"<span class=\"hljs-title\">password<\/span>\" <span class=\"hljs-title\">name<\/span>=\"<span class=\"hljs-title\">password<\/span>\" <span class=\"hljs-title\">placeholder<\/span>=\"<span class=\"hljs-title\">Password<\/span>\" <span class=\"hljs-title\">required<\/span> <span class=\"hljs-title\">class<\/span>=\"<span class=\"hljs-title\">form<\/span>-<span class=\"hljs-title\">control<\/span> <span class=\"hljs-title\">mb<\/span>-2\"&gt;\n    &lt;<span class=\"hljs-title\">div<\/span> <span class=\"hljs-title\">class<\/span>=\"<span class=\"hljs-title\">form<\/span>-<span class=\"hljs-title\">check<\/span> <span class=\"hljs-title\">mb<\/span>-2\"&gt;\n        &lt;<span class=\"hljs-title\">input<\/span> <span class=\"hljs-title\">class<\/span>=\"<span class=\"hljs-title\">form<\/span>-<span class=\"hljs-title\">check<\/span>-<span class=\"hljs-title\">input<\/span>\" <span class=\"hljs-title\">type<\/span>=\"<span class=\"hljs-title\">checkbox<\/span>\" <span class=\"hljs-title\">name<\/span>=\"<span class=\"hljs-title\">remember<\/span>\" <span class=\"hljs-title\">id<\/span>=\"<span class=\"hljs-title\">remember<\/span>\"&gt;\n        &lt;<span class=\"hljs-title\">label<\/span> <span class=\"hljs-title\">class<\/span>=\"<span class=\"hljs-title\">form<\/span>-<span class=\"hljs-title\">check<\/span>-<span class=\"hljs-title\">label<\/span>\" <span class=\"hljs-title\">for<\/span>=\"<span class=\"hljs-title\">remember<\/span>\"&gt;<span class=\"hljs-title\">Remember<\/span> <span class=\"hljs-title\">Me<\/span>&lt;\/<span class=\"hljs-title\">label<\/span>&gt;\n    &lt;\/<span class=\"hljs-title\">div<\/span>&gt;\n    &lt;<span class=\"hljs-title\">button<\/span> <span class=\"hljs-title\">class<\/span>=\"<span class=\"hljs-title\">btn<\/span> <span class=\"hljs-title\">btn<\/span>-<span class=\"hljs-title\">primary<\/span>\"&gt;<span class=\"hljs-title\">Login<\/span>&lt;\/<span class=\"hljs-title\">button<\/span>&gt;\n&lt;\/<span class=\"hljs-title\">form<\/span>&gt;<\/span><\/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>The login form accepts an email and password, and optionally a \u201cremember me\u201d checkbox to keep the user logged in across sessions.<\/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\">\/\/ resources\/views\/dashboard.blade.php<\/span>\n\n&lt;div <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span>=\"<span class=\"hljs-title\">container<\/span> <span class=\"hljs-title\">py<\/span>-5\"&gt;\n    &lt;<span class=\"hljs-title\">h1<\/span>&gt;<span class=\"hljs-title\">Welcome<\/span>, <\/span>{{ auth()-&gt;user()-&gt;name }}!&lt;\/h1&gt;\n    &lt;p&gt;You are logged in.&lt;\/p&gt;\n\n    &lt;form method=<span class=\"hljs-string\">\"POST\"<\/span> action=<span class=\"hljs-string\">\"{{ route('logout') }}\"<\/span>&gt;\n        @csrf\n        &lt;button <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span>=\"<span class=\"hljs-title\">btn<\/span> <span class=\"hljs-title\">btn<\/span>-<span class=\"hljs-title\">danger<\/span>\"&gt;<span class=\"hljs-title\">Logout<\/span>&lt;\/<span class=\"hljs-title\">button<\/span>&gt;\n    &lt;\/<span class=\"hljs-title\">form<\/span>&gt;\n&lt;\/<span class=\"hljs-title\">div<\/span>&gt;<\/span><\/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>The dashboard displays the logged-in user\u2019s name and provides a logout form. The <code>auth()<\/code> helper makes the authenticated user available in views.<\/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<h2 class=\"wp-block-heading\"><strong>5 &#8211; Protecting Routes with Middleware<\/strong><\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>We already wrapped our routes in <code>guest<\/code> and <code>auth<\/code> middleware. This ensures only the correct type of user can access each page. For example, if a logged-in user tries to go to <code>\/login<\/code>, they\u2019ll be redirected away, and if a guest tries to reach <code>\/dashboard<\/code>, they\u2019ll be blocked.<\/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<h2 class=\"wp-block-heading\"><strong>6 &#8211; Common Errors<\/strong><\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Invalid CSRF token<\/strong><br>Always include <code>@csrf<\/code> inside your forms. If missing, Laravel will reject the request with a 419 error.<\/p>\n\n\n\n<p><strong>Session not persisting<\/strong><br>Check your <code>.env<\/code> file for correct <code>APP_URL<\/code> and <code>SESSION_DOMAIN<\/code> settings. Also verify that cookies are enabled in your browser.<\/p>\n\n\n\n<p><strong>Too many redirects<\/strong><br>This usually means routes are protected incorrectly. For example, if your dashboard route is missing <code>auth<\/code> middleware, or if your login route isn\u2019t wrapped in <code>guest<\/code>, you can end up looping.<\/p>\n\n\n\n<p><strong>Password not hashing<\/strong><br>Make sure you use <code>Hash::make()<\/code> when storing passwords. Storing plain text passwords is insecure and will break login attempts.<\/p>\n\n\n\n<p><strong>Email already taken<\/strong><br>If you try registering twice with the same email, the validation rule <code>unique:users<\/code> will stop it. This is expected behavior to keep emails unique.<\/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<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>You now have a fully functional authentication system in Laravel 12 without relying on Fortify. You created routes, a controller, and Blade views for registration, login, and logout \u2014 plus middleware protection and error handling. This hands-on approach helps you understand how authentication really works in Laravel, and gives you a foundation to expand with features like email verification, roles, or password resets later.<\/p>\n\n\n\n<p><\/p>\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Next Steps<\/strong><\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>Now that you have the basics of authentication working, here are some features you can explore next to make your app production-ready:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Password Reset:<\/strong> Allow users to reset their password using email tokens.<\/li>\n<li><strong>Email Verification:<\/strong> Ensure new users confirm their email before accessing protected areas.<\/li>\n<li><strong>Social Logins:<\/strong> Add Google, GitHub, or other OAuth logins with Laravel Socialite.<\/li>\n<li><strong>Roles and Permissions:<\/strong> Restrict actions with role-based access control (e.g., Admin, Editor, User).<\/li>\n<li><strong>Security Enhancements:<\/strong> Enable two-factor authentication (2FA) for sensitive accounts.<\/li>\n<\/ul>\n\n\n\n<p>These additions help secure your app further and provide a better user experience as your project grows.<\/p>\n\n\n\n<p><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Authentication is one of the first features developers add to a new Laravel project. While Laravel Fortify provides a robust solution, sometimes you want to implement basic login, registration, and logout yourself to keep things simple or learn how it works under the hood. In this guide, we\u2019ll build a lightweight authentication system in Laravel [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":128,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[12,13],"class_list":["post-126","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\/126","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=126"}],"version-history":[{"count":1,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts\/126\/revisions"}],"predecessor-version":[{"id":127,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts\/126\/revisions\/127"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/media\/128"}],"wp:attachment":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/media?parent=126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/categories?post=126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/tags?post=126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}