In this video we are going to learn about Creating Admin and User Authentication
For authentication here I am going to use laravel/ui Package
I have already installed the laravel/ui package in previous video
Now lets customize this
First of all open the user migration
And here add a column

$table->string('utype')->default('USR')->comment('ADM for Admin and USR for User or Customer');

Now lets refresh the migration
Run the command in command prompt

php artisan migrate:refresh

Now lets create a middleware for the admin
So run the command

php artisan make:middleware AuthAdmin

Now open the This AuthAdmin middleware from App\Http\Middleware
And inside the handle method add the following

if(Auth::user()->utype != 'ADM')
return redirect()->route('login');

Now go to the App\Http and from here lets open Kernel.php file
Inside the middleware Aliases add here

'auth.admin' => \App\Http\Middleware\AuthAdmin::class,

Now go to the App\Providers directory and from here open RouteServiceProvider.php file
And here from this const Home variable just remove this home only add here forward slash (/)

public const HOME = '/';

Now lets create two controller one for the user and another for the admin
So run the command in command prompt

php artisan make:controller UserController
Php artisan make:controller AdminController

Ok controllers are created now lets open these controller
So go to the controller directory and from here lets open the User controller
And add a function inside this controller

public function index()
return view("users.index");

Now open AdminController and add a function

public function index()
return view("admin.index");

Now lets create this index view
So in resources directory
Go inside the views folder and lets open the views directory
And here lets create one for user an and another for the admin
Now inside these folder create index.blade.php file
In this view file add the layout tag here

<h1>User Dashboard</h1>

Similarly in admin index view add here

<h1>Admin Dashboard</h1>

Now lets create route for these
Go to the web.php file
And here add the route for the user and admin



Now go the layout file And here add the menu

<li class="onhover-dropdown">
<div class="cart-media name-usr">
@auth <span>{{ Auth::user()->name }}</span> @endauth <i data-feather="user"></i>
<div class="onhover-div profile-dropdown">
@if(Auth::user()->utype === 'ADM')
<a href="{{route('admin.index')}}" class="d-block">Dashboard</a>
<a href="{{route('user.index')}}" class="d-block">My Account</a>
<a href="{{route('logout')}}" onclick="event.preventDefault();document.getElementById('frmlogout').submit();" class="d-block">Logout</a>
<form id="frmlogout" action="{{route('logout')}}" method="POST">
<a href="{{route('login')}}" class="d-block">Login</a>
<a href="{{route('register')}}" class="d-block">Register</a>

Now all done so lets check
So run the application

Php artisan serve

Now go to the Localhost:8000
Here is the login and register link
Now lets register two user one for the admin and another for normal user
Now user created lets logout and register another user
Now go to the phpMyAdmin
And lets open the database
And browse the users table
Now edit this record and change the utype as ADM for the admin user
Now lets check this so logout from here
Now lets login with admin credential
Here is the admin dashboard
Now if I login with user credentials you can see the user dashboard is here
If I want access admin page it will redirect us on login page
So in this way you can create Admin and User Authentication for the Ecommerce Project
so that's all about Creating admin and user authentication.