Laravel 10 Multi Guards Authentication system full tutorial | with laravel breeze

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello guys uh in this video I will show you to how to make multi guard authentication system so I will explain it uh step by step so you can learn it by step by step okay first we need to make uh fresh Lal project so [Music] first I need to go to my exam folder uh you can uh make it anywhere you want uh but uh I make the project in uh my exam folder okay uh in the exam folder HD Docs and uh I'm going to open Terminal composer create project LEL slash [Music] LEL uh I'm calling to project Pro name project 20 project 20 okay okay installing L uh project is creating okay it's done so uh I create created the Lal project project name is uh project 20 so uh now uh I need to close this window and this is the project we created project 20 and I need to open exam and uh start start okay now I need to open this in visual code so open the terminal and type code Dot and enter so it's open in usual code so don't want this and this is my project so uh first I need to uh change my database name so I need to make database I can uh make database from here okay uh no need to use this uh this is you can see my databases uh so I need to make a new database uh I named it uh project 20 Pro 20 okay uh in the en example file I create it pro 20 all right so now um I need to install Lal Breeze okay so I need to go to official website of Lal okay you can search uh letter breeze so uh you need to run these codes in your terminal okay first you need to copy this code and run this in visual code so open the terminal and new terminal uh paste it okay run okay it's done so now you need to run other codes uh you need to install this uh Bree package so copy it and paste it uh so don't uh run this okay uh you need to type this blade blade okay uh now you can run okay okay it's done so you can now uh paste the code uh PHP Artis migrate uh and run it okay it's says uh uh database Name Pro 20 does not exit so uh would you like to create it uh I didn't create uh the database in my SQL database I uh change the name to Pro 20 but I didn't create it okay uh from here you can create it okay you need to uh say yes y s yes okay database is created uh and uh we need to copy this code now npm install copy and paste okay now uh you need to copy npm [Music] runu and paste okay everything is done uh so you can close the you close your browser okay you can close it uh now you need to make tables so in my case uh I need to create table like students uh editors moderators so uh I want to add uh guards like Student Admin editor so uh now I need to create tables student table editor table and admin table okay so first I need to make model so uh you know the code for create model so it's PHP art [Music] is make model so I create table for students so model name is student student and I need need to create migration file so I type uh minus M it's created the model and its migration file so uh likewise I need to make model for admin PHP artisan make model admin it's created admin table and admin's migration file so I need to make model 4 editor [Music] so I created three models admin student and editor [Music] so this is my models I already created and user model is provided [Music] so okay now I need to uh some changes in uh in the model okay uh I need to make some changes so this is important okay in your project uh I know you have different tables so when you need to make uh different guards for your tables uh please uh try my methods okay um I'm going to copy the user model okay I going to copy user model you can see this is uh user model uh LEL proide okay this is user model so and uh you can see this is uh migration file users migration file you can see the fields okay you can see the fields uh so in our admin's migration file it's uh it has two columns ID columns and time stamps so I'm going to make my tables like uh user table you can add your custom columns to your tables uh but uh this is easy for me so I'm going to to add this columns in uh users table I'm going to copy it and paste my tables migration files so in admin table I'm going to paste it and the editors table I'm going to paste it and student table also so it's done I need to make changes in models okay so I'm going to copy all the code in uh user model select all and copy okay I'm going to paste it in my uh other models okay I'm going to paste it in this model okay this is admin model so I need to change the class name for admin so and also paste it for student model and change the class name for for student and paste it for editor [Music] table change the class name for editor right so I told you I need to make guards for my tabl so uh I need to make admin guard uh editor guard and and student got so uh please uh put this code in your models okay protected C so this is editor model no so my guard name is editor okay I didn't create the guards yet uh I will create it but uh you can understand it okay uh the guard name is editor uh I will create it uh but I need to um put it here okay uh guard name is editor editor uh I used simply okay okay likewise I need to uh copy this code and paste it in admin uh model but uh in the admin model I used uh guard admin guard so I change it to admin okay uh in the student model I'm going to use student guard so I change it to student right database site is almost done so I need to uh migrate refresh okay so PHP artison migrate refesh uh I need to run this code and so it's all done you can see it in your browser uh I created uh project 20 where is it this and you can see the tables admin table editor table but uh I didn't add uh data for this taable so we need to add data for this tables but we can't add uh datas from here because uh we need to uh add uh uh you know the password uh must be hashed okay so we can use uh C the method for add data uh uh in next video I will I will show you how to add uh data for the tables so I think this is uh enough for today [Music] so so in this video I will show you to add uh data to your tables using Ceda method okay uh so uh you need to uh make uh factories for your tables first you need to make uh Factory for admin table so PHP artisan make Factory I uh name it uh admin Factory admin Factory so enter you can see admin Factory is created you can see the factories in uh database factories okay uh you can see new file admin Factory file and I need to make factories for other table so admin Factory and we need to create editor Factory editor Factory and we need to create student Factory okay now you can see uh no uh data in here now you need to go to admin Factory and uh add this code okay uh you can uh copy this code from uh my uh source code I provided this is uh this data for admin table okay uh so admin email is admin gmail.com uh admin password is uh this okay uh it's uh this is a hash password for uh uh password okay so admin name I call uh Sandu so but uh it's not admin name the column name is name okay okay you know uh in admin table uh it's uh column name is name so we need to uh change this two name okay right okay uh admin name is is sandun password is this uh and email is admin gmail.com I'm going to add this data to our admin table okay so you can uh I know you need to type this uh code for password so uh you know need to type this uh you can uh copy this uh from my uh uh source code okay uh now uh you need to add this to our table okay so uh you need to go to seeders database seeders okay seeders and database ceders okay uh so it's uh first you come to this uh it's comment okay uh but uh you can uncomment and uh in the brackets uh you need to remove your number okay I think uh in your bracket uh number 10 or something uh so it's uh need to null okay uh and uh table is admin so model is we used admin model okay uh now uh I am going to add the data using database seed okay uh now uh C in database so we can go to admin table and refresh okay admin name is s email is admin gmail.com password is this okay all right now we can add datas to editor table and instent table so I'm going to admin Factory and copy this and paste in edited Factory so I'm going to change email name uh so I'm going to editor editor gmail.com and name is lahu I'm not going to change the password so and uh in instent Factory I'm going to paste it and email is uh student at gmail.com so password is this and name is I'm going to uh do okay all right I need to uh SE this so I'm going to I'm not going to see the admin table so I'm going to comment this okay and copy now I'm going to see editor aable and instrument table so uh I'm going to uncomment this and uh so uh you can use this codes for editor editor editor and student so so uh when we run these codes uh the data in editor Factory and student Factory uh are going to uh our tables okay uh I already add data to admin uh table so I I comment this code now I'm going to add data to editor and instent table so I am going to run this okay so I am going to now again PHP Artis database seed and PHP Artisan database seat okay run this code okay okay right uh we can see what happened editors table you can see the editor editor gmail.com and inst table you can see uh okay this is how we can add data to uh table okay uh you can see uh I used has password [Music] so uh this is very easy method this video is not necessary okay if you have another method to add uh data to your tables it's all right okay you can use your own methods okay uh this is the easy method for me okay uh because of that I use it um [Music] so this video is over so in next video uh we can create uh guards okay see you in next video [Music] in our last video we added uh data to our uh tables in our database so uh you can do it uh with your own uh method okay if you have any other method to add uh data to your database you can uh use that method okay uh okay now we need to make guards okay uh in this video I will show you to uh how to make guards okay you know uh in our database uh we have student table admin table and editor table so I need to uh make uh student guard admin guard and editor guard okay so I'm going to make the guards so uh it's in uh config and O Okay config o so this is default guard okay this is default guard uh guard name is web so we can add new guards to here okay uh please copy this and uh paste here okay now you can uh add guard name okay uh I'm going to add admin guard so admin admin guard uh driver is session provider is it must be uh admins admins this is admin and this is admins okay okay now uh I'm going to add uh student guard okay student guard so I paste it here again and guard name is student student and uh provider is students so for the student guard provider is students for the admin guard provider is admins okay now I am going to again paste it and I'm going to make editor card editor okay provider is editors all right okay uh now uh I need to add providers okay you know these are the providers editors students and admins so I'm going to copy this line and paste here and uh you know our admins provider no admins we create that admins provider so for the admins provider model is admin model OKAY admin model I paste it here again and this is for editor editors provider editors editors provider for the editors provider model is must be editor model okay now I'm going to paste it here again and uh this is for students provider students and for the students provider model must be student model all right that's all uh we created the all guards okay that's all so uh in next video uh we can make uh middle okay so guys uh please subscribe my channel see you in next video [Music] [Music] okay hello everyone in this video I'm going going to tell you how to make uh middle okay uh this is very easy uh I'm going to make admin middle and editor middle and student mid okay so we can make middle using this simple code okay PHP Artis make middleware okay pH Artis make midw what is the middleware we make admin middleware so so I'm going to make admin mid layer so pH make mid layer admin okay now I'm going to enter this so you can see uh in the HTTP sorry app HTTP middleware and uh you can see our new middleware admin okay this is our new midd admin midd Okay so I'm going to change something in here uh before that I'm going to make uh our other middle lay okay it's uh PHP add make middle lay I'm going to now create student mid now I'm enter this okay it's created and I'm going to make uh editor middle editor mid okay PHP make midle editor okay admin middle stent midle and editor middle are created okay now I'm going to uh make some changes in uh admin M okay when I change it uh and uh I can uh copy and paste it for other MERS okay okay uh please uh type this use o okay I'm going to use so uh now you need to please do it with me okay if what [Music] God admin okay uh if uh guard is not admin okay this means uh it's check uh and [Music] uh authentic user is uh not the admin uh we need to uh redirect the user to uh login page no so when he is not admin uh we need to redirect uh him to uh admin login page so we can handle it uh from here okay [Music] so if he is not a admin uh we need to return redirect route admin login okay uh I am not created this route yet but I will create this route later okay uh when uh user is not admin he will uh redirected to uh admin login okay this very simple you can understand this okay so I need to uh redirect him with message okay with uh there uh should be uh you do not have access you do not have access right okay it's done so uh when user is not uh admin he will redirected to admin login okay so we can uh copy this no you can copy this and uh paste it in other Ms so I copy this and paste it in editor M and you know uh in the editor mid this is should be editor guard is need to editor and uh route uh editor login okay editor login route uh so for the oh I forgot use okay use what right and uh for the stent table and paste the code here and this is student stent [Music] guard student guard and this is student log stent l so it's done and uh we need to add this middleware to Middle to our kernel okay so please uh open the kernel.php it's in HTTP so uh in the M uh part you can add our new Midas okay you can simply copy this and uh paste it device for our tree M our first middle uh admin uh for it's for admin guard so admin guard and uh mid admin so admin class MD admin class okay right it's for editor this is editor student and this is student student class okay uh now we created the our middle and we add this to our kernel okay uh we created all the guards and midle so now we need to create uh controllers and uh we need to create uh login pages and other things okay uh so we can create [Music] uh uh in this video I'm going to make make uh login views and uh our dashboards okay uh first of all uh uh I didn't make uh any controllers yet uh I want to make that uh I will make it uh in uh next video uh before that I'm going to make a views okay uh I'm going to make uh login for admin uh log for editor and login for student uh if you need to make all logins in uh One login page uh you can do it okay uh but I am uh in this case I'm going to make uh three logins uh uh for your better understanding okay okay in the resources and Views uh we have uh already dashboard View and welcome View uh I'm going to uh make new uh view name uh admin login. blade. PHP okay and uh I need to make other two logins so I'm going to copy and paste remake uh this is for editor login okay editor login. blade. PHP okay now I'm going to make uh student looking student login.php okay this is admin login blade there are no codes in here yet and this is editor login and instent login okay uh now I'm going to make uh this login Pages uh I can uh copy uh this login bade okay uh in the O folder there is a login blade I can copy this okay I can copy all code and paste our login blades okay I can uh copy the editor blade and uh for the student blade okay now okay uh okay this is uh form okay this is form this is uh password field and uh remember me everything in here okay uh this is uh post method you can see and action this is uh route name login okay we don't need that I need to change this um okay I need to uh I'm in student login BL now I need to change this route name okay uh I need to change this route name to uh student login submit okay student login submit okay this is the route uh I am not created this route yet uh I will create it later so likewise uh I can can copy this route and we can uh change the route here okay uh this is for editor login so first uh editors need to uh submit uh their uh passwords email emails then when he click the submit button after the adding email and password uh he will go to this route okay uh the route name is uh not ised login segment it is uh editor editor login submit okay now uh when uh editor submit his email and password then the details uh goes to this route [Music] okay okay and we need to make the changes in this admin login so this is admin login submit and login submit okay now uh you know I I'm not created this uh routes okay uh we can make the that routes uh in next video uh and other things uh we make already uh our login blades admin login editor login and inst login you don't need to use this uh login blade file okay you can create your own uh login blade uh using uh adding uh form for password and email I copy this uh login blade uh because uh it is very easy to me uh now I am going to make uh dashboard uh blades uh I'm going to make three dashboards admin dashboard editor dashboard and student dashboard okay admin dashboard blade. PHP okay and I need to make uh editor dashboard do. PHP and I need to make student Das board do B do BP right admin dashboard editor dashboard and student dashboard okay in admin dashboard uh I'm going to make uh uh simple dashboard uh this is not a dashboard uh uh in the body section uh I'm going to uh header uh welcome uh this code is uh you can use this code for uh when user is authenticated uh you can show his uh name or email or something uh using uh the table uh so you can use this code okay uh uh this code uh will show you uh what is the uh usern name okay uh in my case our admin table we can see our admin table this is our admin table you can see the name column okay uh this is name column so when uh this user uh login uh the code will show you the uh name okay I think you can understand that [Music] so uh when you change this to email uh it's showing the users email okay okay uh you can see email field I can add this I can add this uh I can uh copy this and paste here and this is I can change this email okay your email is okay this is email this is username okay right uh I can copy this for other dashboards this is for editor dashboard uh uh the guard is need to editor editor okay editor right this is editor dashboard this is editor dashboard okay uh I'm going to copy this to student dashboard this is student dashboard and and guardy to student so uh all right everything is fine uh login dates and dashboards are created uh I'm sorry I forgot something I need to uh add uh errors okay I need to add errors to uh uh login Fields uh so I'm going to add erors okay so take some space in here uh now please uh type this uh I already typed this and uh I can paste it but you need to uh type this okay uh this is code section you need to type this code uh you can type this uh using watching the video okay uh you need to copy this and uh you can paste it in uh editor login editor login and the student login okay codes are fine now uh in next video we can make uh routes and controllers [Music] okay this video we need to make uh controllers uh we need to make admin controller editor controller and instrument controller and uh inside the this admin controller we need to make uh dashboard method login method and uh login submit method and uh log out method okay uh so I'm going to create this uh first we need to uh make controller okay uh so you know the code so PHP Arison make controller make controller space and uh name is admin controller okay admin controller is created and we need to make editor controller same code editor and we need to make student controller finished okay uh I'm going to first uh admin controller okay HTTP controllers admin controller okay uh first I'm going to fill this controller first of all uh we need to make uh dashboard method okay public function dashboard okay uh inside the dashboard method uh return view I need to uh return admin dashboard okay admin dashboard right I need to make another method uh for login okay public uh function login okay return view I need to return the admin login page okay admin login view uh admin login okay I need to return admin loog I already create admin login and admin dashboard uh because of that uh you can underline okay you can see this underline uh I need to create uh another method um it's for login submit okay uh when you user uh try to uh enter the login details uh that details come to this method okay public [Music] function login submit okay so uh when user enter the login details uh email and password and he need to uh click submit button uh when click the submit button that data comes to uh this method we need to get that uh details uh I'm using uh request method uh request method sorry so I'm going to get that data to uh object uh so I'm going to create uh object uh request you can use uh any name for that okay uh so that data comes to this object okay so first of all we need to validate no [Music] so we need to validate that data so validate what are the data uh comes to this object uh email and password no so email and password so I'm going to validate email uh required and uh uh it's email okay you can uh validate uh this data uh with your own uh methods okay uh I'm going to edit password it's required done okay uh now I'm going to uh make object credentials uh so uh this uh object is equals to uh uh data from uh request uh object uh so I need to uh only email and password so you know in the login uh blade uh sometime uh I don't know what is your uh Fielding uh login page uh when uh user uh click the submit button that all data uh comes to this request object but I need to only email and password so I'm going to uh get uh only email and password from request object okay so it's equals to credentials object so I'm going to get only uh email and password only email and password okay right okay now we need to make authentication uh part if uh what guard guard is admin okay uh in this case guard is admin user need to uh be admin okay uh attempt so if uh this uh user is admin when his uh credentials match to uh admin table uh data um he need to login so uh he must need to login so so we can let him to log okay uh so return we [Music] direct we need to redirect him uh admin login sorry uh we need to redirect him to admin dashboard no when user is login uh he need to go admin dashboard okay route uh admin dashboard sorry uh this route to simple okay admin dashboard route uh I'm not created that route yet and uh I need to uh successful uh message uh to show okay with u i can say uh login successful log okay now when he's not uh uh he's not in admin table what happened uh else we need to redirect him to admin login no so turn redirect to uh route I need to redirect him to uh admin login admin login route okay uh I need to show message uh login unsuccessful message okay with UHA login sorry login on success for okay uh login submit method uh is uh over so now I need to make uh log out method it's very easy okay public [Music] function log out okay uh God admin so uh log out log out function okay uh and uh return when he click the log out button uh he need to redirect it to uh admin login so turn redirect route we need to redir him to admin log with success message what is the success message log out successfully okay uh all uh all methods are done so I need to add this use hash use what and use app slash model slash admin model and uh we need to uh add uh use I can copy this okay I can copy this and paste uh I can edit this to uh support support SDR and uh that's all uh I can uh copy this controller detail to uh other controllers okay I'm going to copy this and you know what are the changes uh we can uh change all admin uh names to editor okay we can change all this to editor in editor controller and we need to uh change all this to student in student control okay I'm going to do that and I'm going to copy all l paste in editor controller uh I don't need this code and paste okay uh let's check uh app httv controller say uh use model admin we do needit admin model and uh you know uh class is not admin controller class is uh editor controller okay uh so uh and uh uh return view is not admin dashboard it's uh must be edited dashboard okay and uh not admin login it must be editor login so you can see other things and uh these all need to edit I'm going to uh click this and I'm going to click alt okay alt uh pressing the alt button I can click uh all this code okay uh you can see uh I'm not going to uh s uh these parts uh now I can uh change uh this uh admin to editor editor okay you can see uh all the uh selected places are edit okay edit a login edit a dashboard editor login why it's not underline I created that view we can see use editor login edit T [Music] login oh you can see double dot here name right uh again to editor control yeah you can see underline uh okay uh we need to uh change these parts uh okay okay 1 2 3 4 5 6 uh pressing old button and uh I can change all the places editor okay editor controller is done done so now I'm going to change this in instrument controller I am going to delete that and paste here and I'm going to change this admin to student okay pressing all button I can do that okay right and I'm going to change this all bases to student right controllers are done uh in next video we can make uh routes okay bye okay in this video I'm going to make uh routes okay uh I need to make uh routes for our dashboards uh logins and uh uh our methods okay now uh so I'm going to uh routes folder and going to web.php you can see some routes in here by default uh at first I'm going to make routes for admin okay okay uh so you can see this is uh routes for admin uh you can see I'm using middle uh I'm using admin middle uh for uh admin dashboard route okay uh when uh called admin dashboard [Music] uh it's going to work uh this route okay this route and it is a admin controller uh method is dashboard uh you know this method uh in the admin controller has a dashboard method uh so we can see that uh admin controller and dashboard method this is dashboard method uh so when uh call this dashboard method uh it's uh view uh return this view admin dashboard view okay [Music] so you can type this uh routes uh within this video okay uh I'm using uh prefix uh admin uh you know the freefix uh used to uh sort the uh route okay now uh SL Lin means uh admin SL login okay uh log out means uh ad admin SL L log out okay likewise uh admin SL login submit okay uh I'm using prefix for that uh so it's not uh need to okay uh and this is uh login route okay uh this route called admin login when uh admin login route call uh this uh method is working uh it's in uh admin controll uh this uh login method is in uh admin controller uh when uh this is admin control and this is the login method okay uh when call this uh method it's view admin login view okay and uh when call admin log out uh route uh it's call in this uh log out uh method it's in uh admin controller okay uh this is very important route admin login submit route okay um when this uh route calling uh this method is working okay and uh this is post method okay uh this is for you know uh when uh uh user uh going to uh type his email and password and uh click the submit button uh that all data goes to uh login submit method okay so this route for that uh route name is admin login submit okay you can see that uh admin login uh blade admin login blade you can see this is the route okay when uh user uh type the password and uh type the email and uh click the submit button uh that data goes to this route okay this route admin login submit route okay admin login submit okay uh the data uh comes to this route uh so that data goes to admin controller login submit uh method okay uh login submit method in admin controller that data goes to this method okay login submit in admin controller we can see that admin controller login submit okay uh this method uh login subit method that data comes to this method and that data uh we can get to uh request object so I already uh explain this code uh okay that's all and we need to uh make routes for editor and student so I'm going to uh copy this and paste here and you can see uh we need to change this uh admin to editor so I'm clicking old button editor and uh controllers need to admin controller need to change to editor controller that's all likewise uh we need to uh do this to uh student so I'm going to change this to [Music] student this one need to student controller student okay uh routes are done but uh we need to use this uh controllers okay use app SL HTTP [Music] slash [Music] controllers slash admin controller okay likewise we need to copy and paste and paste this must be editor controller and this must be student control okay right uh now we can check uh our project going to terminal and new terminal PHP Artis Ser if anything wrong we can see error uh first we need to go uh our admin login route okay admin SL login admin login route okay uh you can see uh admin login route is working and uh we can uh check uh whether our uh admin user can login no so I can't remember the admin uh user detail this is admin table and uh the admin name is sandun and His email is admin gmail.com password is we know password is password okay uh we can check that okay uh email is admin at gmail. and password this password okay uh I'm going to uh login when uh click the login button you can see this is admin dashboard welcome sandun this is uh that username that admin's name is s okay and admin email is admin gmail.com you can see uh he's uh now uh authenticated user okay uh uh now I need to uh go to uh editor login okay editor login route editor login route and this is editor login route [Music]
Info
Channel: Fixme
Views: 5,901
Rating: undefined out of 5
Keywords: Laravel 10 Multi Guards Authentication system, laravel 10, laravel, login system laravel 10, multi authentication login system, laravel tutorial, multi guards, laravel 10 multi guards, multi guards authentication, authentication, auth, laravel 10 tutorial, laravel 10 project, laravel authentication 10, laravel authorization, laravel guard tutorial, laravel guard vs middleware, laravel multi guard authentication, laravel multi guard auth, laravel breeze, laravel breeze multi auth
Id: c7EZgGVwU60
Channel Id: undefined
Length: 89min 20sec (5360 seconds)
Published: Sun Jan 07 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.