#5 Make Advance E-com Website in Laravel 6.0 | Multi Auth | Guards for Admin | Auth for Users

preview_player
Показать описание
In Part-5, we will start working on Multi Authentication for our Advance E-com website in Laravel 6. We will use Guards for Admins and default Laravel Auth for Users.

We will follow below steps to set Guards for Admin Panel / Admins.

1) Create Migration File
First of all, we will create migration file with name create_admins_table for creating admins table with below columns :-
id, name, type, mobile, email, email_verified_at, password, image, status

So, we will run below artisan command to create migration file for admins :-
php artisan make:migration create_admins_table

Open create_admins_table migration file and add all required columns mentioned earlier.

Now we will run below artisan command to create admins table with required columns :-
php artisan migrate

2) Create Admin model :-
Now we will create Admin model with below artisan command :-
php artisan make:model Admin

We will update content of Admin model file to set protected guard variable for admin and set other variables as shown in video.

We will also extends 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 unauthorised 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 :)
Рекомендации по теме
Комментарии
Автор

Excelent Videos, like the explanation!

joseroman
Автор

Hello,
Thank for such a nice tutorial.

AjaySingh-rjcn
Автор

Hello, thank you so much, but I have a question, in my project I have admin, shop manager and shopper roles, In this case, would it be better to use admins table in database, or give the users admin, shop manager or shopper roles, in short, I want to know, which option would be more correct, which option do people use the most?

sergey_gabrielyan
Автор

First of all sorry if it is too wide of a question. Did I get this correct?
The provider is connected to the table and is part of the guard. The guard protects the model and the middleware protects the routes. If The guard passes, the middleware lets us proceed with the route?
PS great videos

raltychck
Автор

everything works fine i just have a doubt:-
how does the guard in the middleware know whether admin is logged in or not for redirection i know it works using check() but just want to know the process.

gururaj
Автор

is it the admin associative array in the guards in auth.php file checks for admin session?
is it the same array that has been defined in the model assigned to guard variable?
IF YES then on what basis or how does 'driver'=>'session' find whether admin is logged in or not for protecting the route
Waiting for your answer brother....

gururaj
Автор

Thanks sir
Its not redirect perfectly

rehanhussain
Автор

what is different b/w $table->id() and $table->bigIncrement('id') in my case I got make:migration with $table->id();

vishalarora
Автор

Sir I checked again, realized the issue, sorry for the trouble, I have spelled "guard" wrongly. That's why it wasn't working. Thank you

fathimaasma
Автор

Hi thanks for your videos but i have one Question why creating two tables Admin and Users table? Why can't we use one table but different roles of users example if user have user right will be directed to its Interface and when Admin login will be directed to his/her page according to their rights

moriskakengi
Автор

I 've got this error. Trait not found. Pls help me

alokoudapadi-
Автор

Why we write this line in Admin model ? i commented out this line and still i'm not able to access dashboard page. Where its use ?

protected $guard='admin';

Awesome explanation!

Awesome explanation.

imran
Автор

Argument 2 passed to must be an instance of Illuminate\Contracts\Auth\UserProvider, null given, called in on line 125

getting this error on laravel 8 followed ur video totally .

ianrifadsha
Автор

why do you separate admin to users? If you use an role/permissions es.spatie You can use a single table with users and admins

davidespigolon
Автор

Hi sir in this tutorial I am facing that error kindly help with it
Method does not exist.
I am following all steps you did in the tutorial. I am working on laravel 8

MuhammadImran-tbxy
Автор

why we use authenticable and notifaible ???
i dont understand?

mkguru
Автор

Hello Sir, Can you please make an video for Guards authentication using Laravel8 and Mongodb. I had tried with same logic using mongodb but its not working. Please sir i am badly need of that. Will be waiting for your reply.

sourabh
Автор

sir i got error
whenever i type dashboard ...error comes
"
BadMethodCallException
Method does not exist.

Bad Method Call
Did you mean ?
"

plz help me out

kazimustakim
Автор

Sir Custom Auth login for users thnx. ... don't use default make:Auth

MuhammadAdnan-gxrd
Автор

can you help me, please!!!

BadMethodCallException
Method Illuminate\Routing\Route::get does not exist.


i can't solve this error.

afiaanjum