Laravel 11 Tutorial (with MongoDB): [ Ссылка ]
This is Part 6 of the Laravel 11 Tutorial in which we are building the e-commerce website with Laravel as the front end and MongoDB as the backend. 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 the 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 comment Illuminate\Database\Eloquent\Model and add below MongoDB classes.
use MongoDB\Laravel\Auth\User as Authenticatable;
use Mongodb\Laravel\Eloquent\Model as Model;
We will also 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.
3) Update auth.php file:-
We will update the auth.php file located at config\auth.php to set guards for admin to assign session in driver and admins in provider as shown in the video.
We will also set providers for admins to assign eloquent in driver and Admin classes in the model.
4) Create Admin Middleware:-
Now we will create an Admin Middleware file by running the below command:-
php artisan make:middleware Admin
5) 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.
6) Update app.php file:-
Now we will update the app.php file located at bootstrap\ folder to register Admin middleware as global as shown in the video. (Major change in Laravel 11 to register Middleware)
Instead of registering middleware at kernel.php, we need to register it at app.php file in Laravel 11.
7) Update web.php file:-
Add the admin middleware group and move the admin dashboard route under it to protect it from unauthorized access.
Now no one can access the admin dashboard without logging into the admin panel. We have used Guards to protect the admin routes including the dashboard route.
In the next video, we will create the admin record with the username and password with which we are going to log into the admin panel.
Thanks for watching :)
►Click here to subscribe for Laravel & other updates - [ Ссылка ]
Popular Stack Developers Series that can help you:-
►Laravel MongoDB Tutorial: [ Ссылка ]
►Laravel 10 Tutorial Playlist: [ Ссылка ]
►Laravel Multi-Vendor E-commerce Website - [ Ссылка ]
►React JS Tutorial for Beginners with Laravel - [ Ссылка ]
►Laravel Tutorial for Beginners - [ Ссылка ]
►GIT Tutorial for Beginners - [ Ссылка ]
►Laravel API Tutorial - [ Ссылка ]
►Laravel Interview Questions - [ Ссылка ]
►jQuery Tutorial - [ Ссылка ]
►Laravel Basic E-commerce Series - [ Ссылка ]
►Laravel Dating Series - [ Ссылка ]
►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
►Like Facebook Page to get updates - [ Ссылка ]
►Join Facebook Group to resolve your queries - [ Ссылка ]
►Follow on Instagram - [ Ссылка ]
►Follow on GitHub - [ Ссылка ]
#laravel11 #laravel #mongodb #mongodbtutorial
![](https://i.ytimg.com/vi/p94WxPSOm0s/maxresdefault.jpg)