filmov
tv
Laravel 10 Tutorial #6 | Create Admin Middleware to Protect Admin Routes | Multi Authentication
![preview_player](https://i.ytimg.com/vi/HmqIqRYgnO4/maxresdefault.jpg)
Показать описание
Welcome to Part-6 of the Laravel 10 Tutorial in which we are first creating the admin panel. In this video, we will work on Multi Authentication in which we will use Guards for Admins and default Laravel Auth for Users.
We will follow the below steps to set Guards for Admin Panel / Admins.
1) Create admins table:-
First of all, we will create an admins table with migration with the below columns:
id, name, type, mobile, email, password, image, status
So, we will run the below artisan command to create a migration file for admins:-
php artisan make:migration create_admins_table
Open the create_admins_table migration file and add all required columns mentioned earlier.
Now we will run below artisan command to create an admins table with the required columns:-
php artisan migrate
2) Create Admin model:-
Now we will create an Admin model with the below artisan command:-
php artisan make:model Admin
We will update the content of the Admin model file to set the protected guard variable for admin and set other variables as shown in the video.
We will also extend the Admin class to Authenticatable and add its namespace as well.
We will also set providers for admins to assign eloquent in driver and Admin class in model.
4) Create Admin Middleware :-
Now we will create Admin Middleware file by running below command :-
php artisan make:middleware Admin
6) Update Admin Middleware
Add Auth:guard check in Admin Middleware to protect the admin routes. This check will be false for now as we have not registered the admin guard yet.
Add admin middleware group and move admin dashboard route under it to protect it from unauthorized access.
Now no one can access admin dashboard without login into the admin panel. We have used Guards to protect the admin routes including dashboard route.
In next video, we will work on admin login and logout functionality. We will register admin guard every time when admin logged in and destroy it every time when admin logged out from the admin panel.
Thanks for watching :)
Popular Stack Developers Series that can help you:-
►Join this channel to get the complete source code of all series:
Follow Stack Developers on Social Media to get updates and resolve your queries
#laravel10 #laravel10tutorial #laravel
Комментарии