Laravel 8 Multi Auth (Authentication) Tutorial

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

In this Laravel 8 Multi Auth (Authentication) Tutorial I’ll show you how to create multi auth login in laravel. In this tutorial you will learn to create multi auth login system using middleware in laravel 8. In this article I’ll share example of Multiple authentication system multiple users can log in in one application according to their roles.

When we want create separate user login or separate user/admin panel for users with different privileges or access rights in same application. With multi auth system we can allow different user to access different panel in application. In this example 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.

Laravel 8 Multi Auth (Authentication) Tutorial

In this step by step tutorial you will learn about Multi Auth login in laravel. I will also demonstrate you to create laravel multi auth login using custom middleware. Please follow the instruction given below:

Step 1: Install Laravel 8

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

Step 2: Database Configuration

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.

Step 3: Update Migration and Model

Now we will add new column “is_admin” in users table and model.

database/migrations/000_create_users_table.php

app/Models/User.php

Now, run following command to migrate database schema.

Step 4: Create Auth using scaffold

Now, we will generate laravel auth scaffold to create login, register and dashboard.

Laravel 8 UI Package

Generate auth

Step 5: Create IsAdmin Middleware

app/Http/middleware/IsAdmin.php

app/Http/Kernel.php

Step 6: Create Route

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Step 7: Add Method on Controller

Now add adminHome() method for admin route in HomeController.

app/Http/Controllers/HomeController.php

Step 8: Create Blade file

In this step we will create a new blade file for admin and update for user’s blade file as well.

resources/views/home.blade.php

resources/views/adminHome.blade.php

Step 9: Update on LoginController

Now, we will change the LoginController so at the time login we redirect user according to user role. Normal user redirect to home route and for admin user redirect to admin route.app/Http/Controllers/Auth/LoginController.php

Step 10: Create Seeder

database/seeds/CreateUsersSeeder.php

Run the seeder

Now we are ready to run our example so lets start the development server using following artisan command –

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