Laravel 7/6 Multi Auth( Authentication) Example Tutorial

In this tutorial you will learn about the Laravel 7/6 Multi Auth( Authentication) Example Tutorial and its application with practical example.

In this Laravel multi (auth) authentication tutorial I’ll show you how to create multi auth system in laravel 7/6. In Laravel Multiple authentication multiple users can log in in one application according to roles.

Laravel 7/6 Multi Auth( Authentication) Example Tutorial

While developing a laravel application there comes situations where we want create separate user login or separate user/admin panel for users having different privileges or access rights in same application. In this laravel multi auth system, we will create a middleware for checking the user’s role. It is an admin or normal user. We will create middleware name admin and configuration in the kernal.php file and also in the route file.

Install Laravel 6

First of all we need to create a fresh laravel project, download and install Laravel 5.8 using the below command

Configure Database In .env file

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Migrations and User Model

After installing laravel, you will see the some migration files created inside database/migrations directory for creating default create users table and password reset table. Open app/database/create_users_table.php migration file and add/update the following field for admin.

After you added a column “is_admin” to user table run the migration using following command.

After this, go to app/User.php and add is_admin to fillable attribute in the User Model.

Authentication Scaffolding

Laravel comes with in-built basic authentication system, use the below command to generate default authentication scaffolding –

This command will generate required Controller files, views and add routes in our web.php routes file that are required for basic authentication system.

Create Admin Middleware

Now, we will create a middleware that authenticate users. This middleware will help to make sure who can access the admin area or who can access the normal user area. Use the following command to generate a middleware for Admin.

Next, open app/Http/ Middleware/Admin.php file, and here in handle() method implement the logic to authenticate users like below.

Now, we need to register admin route in $routeMiddleware property in the app/Http/Kernel.php file. Lets open app/Http/Kernel.php file and update the $routeMiddleware property like below –

Set Admin Protected Route

Next, create the route for admin. Open the routes/web.php file and add the following code in it.


Create Controller Methods

Open the app/Http/Controllers/HomeController.php controller file and create two separate methods to handle admin and normal users.


Create Blade/View

Now we will have two separate view files, first is for home page and second is for after login admin page. Open the resources/views/home.blade.php file and update the following code.


Here, if(auth()->user()->is_admin == 1) is used to check user is a normal user or an admin user, it will navigate to the admin area. Otherwise, it will redirect to users area.

Now, create a view file called admin.blade.php in the root of the views folder, and add the following code to it.


Start Development Server

Start the development server using following artisan command –

In order to test laravel multi auth system first register a user through laravel register and then change the is_admin=1; and try to login again.

User Home 1 :-


After Login Admin Page :-


User Home 2 :-


In this tutorial we have learn about the Laravel 7/6 Multi Auth( Authentication) Example Tutorial and its application with practical example. I hope you will like this tutorial.