We noticed you're using an ad blocker

Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Laravel 6 multi auth tutorial and code example

world cup 2023

WorldCup 2023

Get update standing, score, poll

Get Now

Are you looking for multiple authentication tutorial and code example for Laravel? Confused continuously seeking tutorial from different laravel article? No more looking forward to multi authentication for laravel framework.

In this tutorial, I'll show you clearly and give code example for how to make multi auth in Laravel 6 step by step natively without any third-party package. Following this tutorial, you can also make multi auth for Laravel 5.5, 5.6, 5.7 and 5.8.

Working Plan

For this tutorial, we'll make the authentication system for 2 user group normal user and admin. For the normal user, we use default auth scaffold and for admin, we have to make some stuff and changes.

Laravel 6 Multiple Authentication steps overview

  • Step 01: Install Laravel 6
  • Step 02: Install Laravel UI
  • Step 03: Database Configuration
  • Step 04: Migration
  • Step 05: Model Setup
  • Step 06: Setup the auth.php config
  • Step 07: Define routes
  • Step 08: Admin authentication controller
  • Step 09: Admin login form
  • Step 10: Handle unauthorized admin redirection

Step 01: Install Laravel 6

Install Laravel 6 with this command. You can do the exact same thing in Laravel >5.5 version also.

composer create-project --prefer-dist laravel/laravel project-name

Step 02: Install Laravel UI

In Laravel 6 by default, make:auth the command is not available. You have to install a package laravel/ui to generate auth scaffold. Keep in mind this is required only if you are using Laravel 6 version otherwise you have to leave this step.

composer require laravel/ui --dev
php artisan ui bootstrap --auth

Step 03: Database Configuration


Step 04: Migration

Make a copy of the user migration file with the name of 2014_10_12_000000_create_admins_table.php


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

class CreateAdminsTable extends Migration
     * Run the migrations.
     * @return void
    public function up()
        Schema::create('admins', function (Blueprint $table) {

     * Reverse the migrations.
     * @return void
    public function down()

save the file and run migration.

php artisan migrate

Step 05: Model Setup

Make an admin model. Here we have copied user model and did some modification.


namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class Admin  extends Authenticatable
    use Notifiable;

    protected $guard = 'admin';

    protected $fillable = [
        'name', 'email', 'username', 'password','email_verfied_at'

    protected $hidden = ['password'];


In this admin model, we have set $guard = 'admin' which we'll configure in auth.php config file later.

Step 06: Setup the auth.php config

Add new guard for admin in guards section.

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

Add a new provider in the provider's section for admin guard provider.

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

Step 07: Define routes

Route::namespace('Admin')->name('admin.')->prefix('admin')->group(function () {
    Route::get('login', 'AdminAuthController@getLogin')->name('login');
    Route::post('login', 'AdminAuthController@postLogin');

Step 08: Admin authentication controller

Let's make a controller for admin authentication with a separate admin folder. So that our admin related controllers will be in the same namespace.


namespace App\Http\Controllers\Admin;

use App\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Str;

class AdminAuthController extends Controller
    use AuthenticatesUsers;

    protected $guardName = 'admin';
    protected $maxAttempts = 3;
    protected $decayMinutes = 2;

    protected $loginRoute;

    public function __construct()
        $this->loginRoute = route('admin.login');

    public function getLogin()
        return view('admin.login');

    public function postLogout()
        return redirect()->guest($this->loginRoute);

    public function postLogin(Request $request)
        $this->validate($request, [
            'email' => 'required|email',
            'password' => 'required|min:5'

        if ($this->hasTooManyLoginAttempts($request)) {

        $credential = [
            'email' => $request->input('email'),
            'password' => $request->input('password')

        if (Auth::guard($this->guardName)->attempt($credential)) {

            return redirect()->intended();

        } else {

            return redirect()->back()
                ->withErrors(["Incorrect user login details!"]);


Step 09: Admin login form

Here I'm showing only login form with minimal design. You can change your required design. Create a login.blade.php file in resources/admin folder.

<form method="POST" action="" method="POST">
        <div class="form-group">
            <input class="form-control" name="email" type="email" required value="">

        <div class="form-group">
            <input class="form-control" name="password" type="password" required>
        <div class="form-group">
            <button class="btn btn-primary" type="submit">Login</button>

Step 10: Handle unauthorized admin redirection

If anyone tries to access admin routes without login as an admin then by default it'll redirect to user login but our goal to redirect to our desired route for admin login route. For doing this we have to change the unauthenticated method in app/Exceptions/Handler.php

protected function unauthenticated($request, AuthenticationException $exception)
        if ($request->expectsJson()) {
            return response()->json(['error' => 'Unauthenticated.'], 401);

        $guard = Arr::get($exception->guards(), 0);
        switch ($guard) {
            case 'admin':
                $login = 'admin/login';
                $login = 'login';
        return redirect()->guest(url($login));

Our desired multiple authentication system is ready to use. We have use middleware to protect admin routes either in routes file or controller constructor according to our needs like below.

In routes

  //here all your admin routes


or by Controller constructor

public function __construct()


Hope this step by step tutorial on Laravel multiple authentications will help you to make your desire multi auth in Laravel application. If you find this helpful please share with others.

Share on

Related Post - Latest Post

Laravel Barcode generation tutorial

What's new in Laravel 9

Make laravel site super fast by page-cache!

Laravel maintenance mode bypass by Secret Route!

Laravel database backup automatically - cPanel shared hosting, VPS

Laravel Datatables - Ajax, Column, Buttons, Customization