• Home
  • Blogs
  • Laravel 12 Multiple Authentication Using Breeze
Blog Details

Laravel 12 Multiple Authentication Using Breeze

If you’re building a modern web application, you’ve probably faced the need to handle different user roles — such as Admin, Agent, and User — each with their own access permissions and dashboards.

laravel 12 makes this process seamless with Laravel Breeze, a lightweight authentication starter kit that can be easily extended for multi-auth setups.

In this tutorial, we’ll create a complete multiple authentication system in laravel 12 using Breeze — step-by-step from installation to dashboard redirection.

By the end of this guide, you’ll be able to log in as Admin, Agent, or User, each having their own dashboard and permissions.


🪜 Step-by-Step: laravel 12 Breeze Multiple Authentication Setup

Step 1: Install laravel 12

If you don’t already have a laravel 12 project, open your terminal and create one using Composer:

composer create-project laravel/laravel example-app

Once installed, navigate to your app directory:

 
cd example-app

Step 2: Install Laravel Breeze for Authentication

Laravel Breeze provides simple and clean authentication scaffolding for Laravel. Run the following commands to install it:

composer require laravel/breeze --dev
php artisan breeze:install
npm install
npm run build

This will create authentication routes, views, controllers, and registration/login functionality.

Tip: Breeze is perfect for beginners — it uses Tailwind CSS and includes everything you need to quickly set up login and registration.


🗄️ Step 3: Create Migration and Update User Model

Now, we’ll add a role column in the users table to define user types (admin, agent, user).

Run the following command:

php artisan make:migration add_type_to_users_table

Update the newly created migration file:

 
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->enum('role', ['admin', 'agent', 'user'])->default('user');
        });
    }

    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn('role');
        });
    }
};

Now, run the migration:

php artisan migrate

Then open the User model and add role to the $fillable array.

app/Models/User.php

protected $fillable = [
    'name',
    'email',
    'password',
    'role'
];

Step 4: Create Role Middleware

We need a middleware that restricts pages based on user roles.

Run the command:

php artisan make:middleware Role

Then, edit the file:

app/Http/Middleware/Role.php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class Role
{
    public function handle(Request $request, Closure $next, $role): Response
    {
        if ($request->user()->role != $role) {
            return redirect('dashboard');
        }

        return $next($request);
    }
}

Now, register this middleware in bootstrap/app.php:

$middleware->alias([
    'role' => \App\Http\Middleware\Role::class,
]);

ip: This middleware will ensure only users with the correct role can access certain routes.


🚦 Step 5: Define Role-Based Routes

We’ll now create separate dashboard routes for Admin, Agent, and User.

routes/web.php

use App\Http\Controllers\AdminController;
use App\Http\Controllers\AgentController;
use App\Http\Controllers\ProfileController;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return view('welcome');
});

Route::get('/dashboard', function () {
    return view('dashboard');
})->middleware(['auth', 'verified'])->name('dashboard');

Route::middleware('auth')->group(function () {
    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});

// Admin Routes
Route::middleware(['auth', 'role:admin'])->group(function(){
    Route::get('/admin/dashboard', [AdminController::class, 'dashboard'])->name('admin.dashboard');
});

// Agent Routes
Route::middleware(['auth', 'role:agent'])->group(function(){
    Route::get('/agent/dashboard', [AgentController::class, 'dashboard'])->name('agent.dashboard');
});

require __DIR__.'/auth.php';

Step 6: Create Controllers for Admin and Agent

We’ll create two new controllers for handling dashboards:

php artisan make:controller AdminController
php artisan make:controller AgentController

AdminController.php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class AdminController extends Controller
{
    public function dashboard()
    {
        return view('admin.dashboard');
    }
}

AgentController.php

 
namespace App\Http\Controllers;

use Illuminate\Http\Request;

class AgentController extends Controller
{
    public function dashboard()
    {
        return view('agent.dashboard');
    }
}

Step 7: Create Blade Views for Dashboards

Create the following files:

resources/views/admin/dashboard.blade.php

<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
            {{ __('Admin Dashboard') }}
        </h2>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6 text-gray-900 dark:text-gray-100">
                    You are logged in as <strong>Admin</strong>!
                </div>
            </div>
        </div>
    </div>
</x-app-layout>

resources/views/agent/dashboard.blade.php

<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
            {{ __('Agent Dashboard') }}
        </h2>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6 text-gray-900 dark:text-gray-100">
                    You are logged in as <strong>Agent</strong>!
                </div>
            </div>
        </div>
    </div>
</x-app-layout>

Step 8: Redirect Users After Login Based on Role

Now let’s modify the AuthenticatedSessionController to redirect users to the correct dashboard.

app/Http/Controllers/Auth/AuthenticatedSessionController.php

public function store(LoginRequest $request): RedirectResponse
{
    $request->authenticate();
    $request->session()->regenerate();

    $redirect = match ($request->user()->role) {
        'admin' => 'admin/dashboard',
        'agent' => 'agent/dashboard',
        default => 'dashboard',
    };

    return redirect()->intended($redirect);
}

Tip: Using match keeps the code clean and readable.

Step 9: Create a Seeder for Admin, Agent, and User

We’ll create some test users using a seeder.

php artisan make:seeder UserSeeder

database/seeders/UserSeeder.php

 
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class UserSeeder extends Seeder
{
    public function run(): void
    {
        User::create([
            'name' => 'Admin',
            'email' => 'admin@gmail.com',
            'password' => Hash::make('123456'),
            'role' => 'admin',
        ]);

        User::create([
            'name' => 'Agent',
            'email' => 'agent@gmail.com',
            'password' => Hash::make('123456'),
            'role' => 'agent',
        ]);

        User::create([
            'name' => 'User',
            'email' => 'user@gmail.com',
            'password' => Hash::make('123456'),
            'role' => 'user',
        ]);
    }
}

Step 10: Run Your Laravel App

You’re all set! Run your Laravel app: 

php artisan serve

Now open your browser and visit:

👉 http://localhost:8000/

You can log in using the following credentials:

Role Email Password
Admin admin@gmail.com 123456
Agent agent@gmail.com 123456
User user@gmail.com 123456

 

Admin Dashboard

Admin Dashboard

Agent Dashboard

agent Dahboard

Users Dashboard

Users dashboard

 

Real-World Example: Why Use Multiple Authentication?

In real-world apps like real estate platforms, learning management systems, or multi-vendor marketplaces, you often need different dashboards and permissions.

For instance:

  • Admins manage users and settings.

  • Agents manage listings or clients.

  • Users access personal data or services.

This role-based authentication system helps you scale your app securely and efficiently.


🏁 Conclusion

Congratulations 🎉 — you’ve successfully built a laravel 12 multiple authentication system using Breeze!

You now have:
✅ Role-based login and dashboard
✅ Middleware for access control
✅ Clean Breeze-powered auth scaffolding

 

Leave A Reply

Your email address will not be published. Required fields are marked

Ahmad

Ahmad Raza

Hi, I'm Ahmad Raza — a passionate Web Developer and Laravel enthusiast.