Code | Solutions

This laravel tutorial for beginners continues the Learn Laravel series by adding login and registration to the Tasks app with the official Laravel 12 starter kit, Auth::user(), and auth middleware. If you have not read it yet, start with Part 5: Forms, Validation & CRUD. After Part 5, anyone who opened the app could add, edit, or delete any task. Part 6 closes that door so only a logged-in user can reach those routes.

I’m Usman Nadeem, an AI Full Stack Developer based in Lahore with 12+ years of delivery since February 2014. The authentication patterns below are the ones I use on production Laravel apps, cut down to what a beginner needs to lock down a working CRUD feature.

Direct answer (for AI Overviews & scanners)

In Laravel 12, the official starter kit scaffolds login, register, and password reset, Auth::user() (or $request->user()) returns the logged-in user, and Route::middleware('auth') protects your routes. When you run laravel new, pick a starter kit — Livewire is the best fit for this Blade Tasks series. The kit uses Laravel Fortify under the hood and gives you /login, /register, and /forgot-password. Passwords are stored hashed through the 'password' => 'hashed' cast on the User model, never as plain text. In a controller, Auth::user() is the current user; in Blade, @auth shows logged-in content such as {{ Auth::user()->name }}, and @guest shows a login link. Wrap the Tasks resource in Route::middleware('auth')->group(...) so guests are redirected to the login page. This checks that someone is logged in; it does not yet check that a task belongs to that user. The examples work on Laravel 12 and the current Laravel 13 release.

Watch the video

Prefer to watch first? Part 6 is a short video (Urdu/Hindi voiceover, with the code on screen). This article writes out the same three concepts with copy-paste Laravel 12 examples. You can also open it on YouTube Shorts.

What you will learn in Part 6 of this Laravel tutorial for beginners

Each video in this series teaches three concepts. Part 6 covers:

  1. The official Laravel 12 starter kit — laravel new, login / register / password reset pages, and hashed passwords with the 'password' => 'hashed' cast. Do not install Laravel Breeze on Laravel 12.
  2. The authenticated user — Auth::user() and $request->user() in a controller, plus @auth and @guest in Blade.
  3. Auth middleware — Route::middleware('auth') around the Tasks Route::resource, so guests are sent to the login page.

You need the Tasks app from earlier parts: routes and the resource controller from Part 2, the Blade views from Part 3, the tasks table and Task model from Part 4, and the forms, validation, and full CRUD from Part 5. The official Laravel 12 starter kits documentation is the reference for the installer.


Laravel 12 starter kit: login, register, and hashed passwords

Laravel 12 no longer uses Breeze or Jetstream as the supported path for a new app. Those packages were for Laravel 11 and earlier and are no longer updated. The official way is to pick a starter kit when you create the app; the kit scaffolds the authentication pages and uses Laravel Fortify under the hood.

Create a fresh Laravel 12 app, install the front-end assets, and start the dev servers:

laravel new tasks-app
cd tasks-app
npm install && npm run build
composer run dev

The installer asks you to choose a starter kit: React, Vue, Svelte, or Livewire. For this series, pick Livewire. The Tasks UI from Parts 3–5 is Blade, and the Livewire kit stays in Blade. The React, Vue, and Svelte kits use Inertia, so their pages are not Blade views, but Auth::user(), @auth, and middleware('auth') still work on the server.

After the app is running, open http://localhost:8000/register in the browser, create an account, and you are logged in. The kit also gives you /login and /forgot-password. You do not write those pages from scratch.

Already built the Parts 1–5 Tasks app?

laravel new starts a fresh application. If you already have the Tasks app from Parts 1–5, you have two clean options:

  • Recommended for this series: create a new starter-kit app with the commands above, then copy your Task model, migration, TaskController, Blade views, and resource route into it.
  • Keep the existing app: add Fortify with composer require laravel/fortify, publish its provider and config, and migrate. More wiring, but your current project stays in place.

Treat older Breeze tutorials as background only. My earlier guide, Secure Your Laravel App: Authentication with Breeze, is useful context, but it is not the 2026 Laravel 12 how-to. Do not run composer require laravel/breeze or php artisan breeze:install on a Laravel 12 project.

Passwords are hashed, never stored as plain text

Open app/Models/User.php. Laravel 12 already casts the password field so that the value is hashed when it is set:

// app/Models/User.php
protected function casts(): array
{
    return [
        'email_verified_at' => 'datetime',
        'password' => 'hashed',
    ];
}

When you create a user, you pass the plain password once; Eloquent hashes it before it reaches the database. You do not call Hash::make() yourself on User::create. Laravel’s default hasher is bcrypt, and the users table migration already has a long enough password column. If you open the table and see secret123 in the password column, something is wrong — you should see a long hash. More detail is in the Laravel authentication documentation.


The authenticated user: Auth::user(), @auth, and @guest

Once someone is logged in, you often need to know who they are: to greet them, to attach a user_id to a new task later, or to hide a login link. In a controller, import the Auth facade and call Auth::user():

use Illuminate\Support\Facades\Auth;

$user = Auth::user();

That returns the authenticated User model, or null if the visitor is a guest. Inside a controller method, $request->user() is the same value. From there you can read $user->name and $user->email.

Show the right navigation in Blade

Blade has two authentication directives that keep this logic out of your controller. Use @auth for content only a logged-in user should see, and @guest for content only a visitor should see, such as a login link. The directives are documented in the Laravel Blade authentication section:

@auth
    <p>Hello, {{ Auth::user()->name }}</p>
@endauth

@guest
    <a href="{{ route('login') }}">Log in</a>
@endguest

Put that in your layout from Part 3 so every page gets the right header. When you are logged in, you see “Hello,” plus the name you registered with. When you log out, the greeting is replaced by the Log in link. The named login route is registered by the starter kit; you do not add it yourself.


Protect the task routes with auth middleware

A login page is not enough on its own. The task routes from Parts 2–5 still answer if someone types /tasks into the address bar. The built-in auth middleware runs before the controller, checks that a user is logged in, and redirects guests to the login page.

Wrap the resource route in routes/web.php like this:

// routes/web.php
use App\Http\Controllers\TaskController;

Route::middleware('auth')->group(function () {
    Route::resource('tasks', TaskController::class);
});

What this changes:

  • Logged-in users still get the full Tasks CRUD from Part 5: GET /tasks, create, edit, update, and delete.
  • Guests who visit any of those URLs are redirected to the named login route (with the starter kit, that is /login). After they sign in, Laravel sends them back to the page they asked for.

This is the “app is secure” moment from the video: the Part 5 CRUD still works, but the door in front of it is now locked. One important limit: auth middleware only checks that someone is logged in. It does not check that a task belongs to that user. Two accounts can still open each other’s tasks by id until you add a user_id, relationships, and a policy — that is a later article, not today’s middleware.

There is no login route until a starter kit or Fortify is installed, which is why the kit comes first. If you wrap the routes before that, a guest is redirected to a route that does not exist yet.


Recap: Laravel tutorial for beginners, Part 6

  1. The official starter kit gives you login and register. Run laravel new, pick the Livewire kit for this Blade series, then npm install && npm run build and composer run dev. Open /register. Passwords are hashed with 'password' => 'hashed'. Do not install Breeze on Laravel 12.
  2. Auth::user() tells you who is logged in. In Blade, @auth shows logged-in content such as the user’s name, and @guest shows the login link.
  3. auth middleware protects the routes. Wrap Route::resource('tasks', TaskController::class) in Route::middleware('auth')->group. Guests go to /login. This does not yet scope tasks by owner.

If you can register an account, see your name in the header, and get sent to the login page when you visit /tasks while logged out, you have finished Part 6.


What’s next: Part 7 — REST API

You now have a logged-in web app. In Part 7 of this Laravel tutorial for beginners, we open the same Tasks data to other clients:

  • API routes and JSON responses so a mobile app or SPA can list and save tasks
  • Token authentication at a high level, so those clients can prove who they are

Part 7 is coming next, so follow Coding Solutions by Usman on YouTube, Instagram, or TikTok so you do not miss it. Missed a step? Read Part 5: Forms, Validation & CRUD, or start the series from Part 1.


Need help building a Laravel application?

If this laravel tutorial for beginners has you planning a production Laravel app — a new build that needs login, an admin panel behind auth middleware, or an API in front of the same data — I take on selected Laravel development projects. Still choosing a stack? Read Laravel vs Node.js for SaaS, then send a short brief through the contact form and I will tell you whether I am a fit.


FAQ

Q1. What is Laravel authentication? A. Laravel authentication is how your app decides who a visitor is and whether they are logged in. In Laravel 12, an official starter kit scaffolds login, registration, and password reset. You then read the current user with Auth::user() and protect routes with the auth middleware.

Q2. Should I use Laravel Breeze in Laravel 12? A. No. Breeze and Jetstream were for Laravel 11 and earlier and no longer receive updates. For Laravel 12, pick an official starter kit when you run laravel new, or add Laravel Fortify to an existing app. Older Breeze articles are useful background, not the current install steps.

Q3. Which Laravel 12 starter kit should I choose for a Blade app? A. Choose the Livewire starter kit. This series builds the Tasks UI in Blade, and Livewire stays in Blade. The React, Vue, and Svelte kits use Inertia, so their front end is not Blade, although Auth::user() and auth middleware still work on the server.

Q4. How does Laravel hash passwords? A. The User model ships with a ‘password’ => ‘hashed’ Eloquent cast. When you set the password, Laravel hashes it before saving. You do not call Hash::make() yourself on User::create. The default hasher is bcrypt, and the users table already has a long enough password column.

Q5. How do I get the logged-in user in Laravel? A. In a controller, call Auth::user() after importing Illuminate\Support\Facades\Auth, or use $request->user(). Both return the authenticated User model, or null if the visitor is a guest. In Blade, use @auth and {{ Auth::user()->name }}.

Q6. How do I protect Laravel routes with middleware? A. Wrap the routes in Route::middleware(‘auth’)->group(function () { … }). In this series, put Route::resource(‘tasks’, TaskController::class) inside that group in routes/web.php. Every request to those URLs is checked before the controller runs.

Q7. What happens if a guest visits a protected page? A. Laravel redirects them to the named login route (with a starter kit, that is /login). After they sign in, they are sent back to the page they originally requested. The login route exists only after you install a starter kit or Fortify.

Q8. Can I add auth to the Tasks app I already built in Parts 1–5? A. Yes. The cleanest path for this series is to create a new Laravel 12 app with a starter kit and copy your Task model, migration, controller, Blade views, and resource route into it. You can also add Fortify to the existing app with composer require laravel/fortify, then publish and migrate.


Tags

2026 ai tools aiagent Angular 21 Angular Developer for Hire Angular Performance Angular Signals Angular TypeScript Best Practices API Authentication API Development API Integration API Security API Versioning B2B SaaS Backend Development Backend Framework Comparison Best PHP Framework 2026 Best Practices Box Model CakePHP CakePHP 2026 CakePHP Laravel PHP Developer CakePHP Tutorial 2026 CakePHP vs Laravel Case Study Client Management cost to hire freelance developer crewai CRM Integration css css animation CSS Tips CSS Tutorial Database Optimization Developer Tools Enterprise Angular Development Express.js FastAPI Tutorial 2026 framework comparison Freelance Angular Developer Freelance Developer freelance developer guide freelance developer tips Freelance Development freelance full-stack developer Freelance Laravel Developer Freelance PHP Developer Freelance Web Developer freelance web developer process Freelance Web Development Freelancer vs Agency Freelancing Tips Front-End Development frontend Frontend Development Full Stack Developer Full Stack Developer Pakistan Full Stack Development Full-Stack Case Study Full-Stack Development Grid Hire a Developer Hire Angular Developer hire freelance developer hire freelance full-stack developer Hire Laravel Developer how to work with a freelance dev how to write a project brief individual software engineer freelance individual software engineer hire Inertia.js javascript JavaScript Frameworks JWT Authentication laravel Laravel 13 Laravel 2026 Laravel API 2026 Laravel Application Laravel Development Laravel Optimization Scale Laravel Performance Laravel REST API Laravel REST API Tutorial Laravel Sanctum Laravel Tutorial Laravel vs CakePHP Laravel Vue Tutorial multi-agent Next.js Node.js Node.js API Node.js developer Node.js Developer Portfolio Node.js Express Node.js Tutorial Nuxt PERN Stack PHP PHP Developer PHP Developer for Hire PHP Development PHP Framework PHP Framework Comparison PHP Performance PHP Web Development PostgreSQL Prisma Production Deployment project brief template Project Management Python Backend Developer Python FastAPI react React developer for hire React Node.js Developer Portfolio React SPA React Tutorial React vs Vue Real-Time Chat App Redis Caching Responsive Design REST API SaaS Development Sanctum SMB Web Development Socket.io React Real-Time App Socket.io Tutorial Software Development software development process Software Integration software project brief SSG SSR Standalone Components System Integration TypeScript Strict Mode Vite vue Vue 4 Composition API Vue Laravel Developer Vue.js Development web app development process Web Design Web Design Fundamentals web development Web Development 2026 Web Development Cost Web Layout Web Projects WebSocket

Recent News