Create Multi-Auth (Admin & User) in Laravel 12

Hi there! In this guide, I’ll show you how to create a multi-authentication system in Laravel 12 for both Admin and User roles. Whether you're building a hosting service, insurance app, credit or loan portal, or even a health or lawyer dashboard, this setup will help you secure your application efficiently.

We'll cover authentication, dashboards, and routing. This beginner-friendly guide is perfect if you're working on projects like a mortgage calculator, donation platform, or any role-based system.

Create Multi-Auth (Admin & User) in Laravel 12

Create Multi-Auth (Admin & User) in Laravel 12

 

Step-by-Step Guide: Multi-Auth in Laravel 12 (Admin & User)

Step 1: Install Laravel 12

Install laravel 12 using the following command.

composer create-project laravel/laravel multi-auth-laravel12
cd multi-auth-laravel12

 

Step 2: Configure Database

In your env file:

DB_DATABASE=multi_auth_db
DB_USERNAME=root
DB_PASSWORD=

Then run:

php artisan migrate

 

Step 3: Create Models and Migrations

Create model and migration using the following command: 

php artisan make:model Admin -m
php artisan make:model User -m

Edit the admins migration:

Schema::create('admins', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->string('email')->unique();
    $table->string('password');
    $table->timestamps();
});

Then run:

php artisan migrate

 

Step 4: Set Up Guards in config/auth.php

Now, setup guards for users and admin.

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'admin' => [
        'driver' => 'session',
        'provider' => 'admins',
    ],
],

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\Models\User::class,
    ],

    'admins' => [
        'driver' => 'eloquent',
        'model' => App\Models\Admin::class,
    ],
],

 

Step 5: Create Authentication Controllers

Create a controller using the following command. 

php artisan make:controller Admin/Auth/LoginController
php artisan make:controller User/Auth/LoginController

In Admin LoginController, add:

use Illuminate\Support\Facades\Auth;

public function showLoginForm() {
    return view('admin.auth.login');
}

public function login(Request $request) {
    if (Auth::guard('admin')->attempt($request->only('email', 'password'))) {
        return redirect()->route('admin.dashboard');
    }
    return back()->withErrors(['email' => 'Invalid Credentials']);
}

Repeat similarly for the User LoginController.

 

Step 6: Create Routes

In routes/web.php:

// User Routes
Route::get('login', [UserLoginController::class, 'showLoginForm'])->name('login');
Route::post('login', [UserLoginController::class, 'login']);
Route::get('/user/dashboard', function () {
    return 'User Dashboard';
})->middleware('auth');

// Admin Routes
Route::prefix('admin')->group(function () {
    Route::get('login', [AdminLoginController::class, 'showLoginForm'])->name('admin.login');
    Route::post('login', [AdminLoginController::class, 'login']);
    Route::get('/dashboard', function () {
        return 'Admin Dashboard';
    })->middleware('auth:admin');
});

 

Step 7: Create Views

Create login pages in resources/views/admin/auth/login.blade.php and resources/views/user/auth/login.blade.php:

<form method="POST" action="{{ route('admin.login') }}">
    @csrf
    <input type="email" name="email" required />
    <input type="password" name="password" required />
    <button type="submit">Login</button>
</form>

 

Step 8: Test Multi-Auth
  1. Visit /login for user login
  2. Visit /admin/login for admin login

Each will redirect to its respective dashboard based on guard.

 

Conclusion

Creating Laravel 12 Authentication with multi-auth for Admin and User is a crucial feature for any modern application—be it for insurance, credit, health, or donation systems. With clear routing, guards, and role separation, your app stays secure and scalable.

 

Frequently Asked Questions (FAQs)

  1. Can I use Laravel Breeze or Jetstream for Multi-Auth?

    Yes, but for more control and customization, manual setup like guards and route groups is often preferred.

  2. How do I handle logout for different guards?

    Use Auth::guard('admin')->logout(); and Auth::logout(); for respective user roles.

  3. Can I add more roles like Lawyer or Donor?

    Absolutely! Just create new models, configure guards, and define route groups for each role.

  4. Does this work with Laravel APIs too?

    Yes, you can use guards with Laravel Sanctum or Passport to apply multi-auth logic to APIs.

  5. How do I redirect based on user type after login?

    Use custom middleware or override the authenticated() method in your LoginController.

 


You might also like:

techsolutionstuff

Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of techsolutionstuff.com. Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.

RECOMMENDED POSTS

FEATURE POSTS