How To Make Multiple Authentication in Laravel 11 Breeze | Multi Role Auth In Laravel Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone this is Yamin and in this tutorial I'm going to show you how you can make Mulo in LEL using Brae so Mulo means we let both and pin and user login and both of them will go to different dashboard and I'm going to show you everything step by step from the very beginning so right now let's go and create a face Lan project so let's go to our over here to this location and we will create an noral project over here so right now we are going to open a common from over here we'll see over here CMD then press inent and in order to create the LEL project we need to run this common composer create project l/ lar let's our project name will be multi you can give any name you want okay this is just a project name so right now if we press enter it will start creating our Lan project so it will take some time so right now I'll just fash for the video so there you can see our project cre is complete so right now if we just close this here you can see we have a project over here multi so right now let's go inside and here you can see this is larel project so right now we are going to open your command prompt in the project directory so that we can run our larel project so let me just over here CMD at the top and press enter and in order to run the project we need to show over here bsp AR sir and press enter and there you can see Server is running so right now let me just copy this and paste it in the browser and press enter so here you can see this is our fated LEL project so right now we're going to add the database name in our project so for it let me just open it using Su test you can use any code editor like gel Studio code or atom and things so right now after clicking the file I'll click over here open folder then we'll just go to the project location and our project is this one Marti select it then select folder and right now I just directly go to the EnV file and over here if you go down here you can see DB connection I'm going to show on here my SQL and here DB database inst stock this one I'm going to show on here multi o you can give the database them anything you want that's fine as well so after giving the name just save it then you can close it and after it let me just go to the browser then we'll go to our PMI admin so make sure your Z is running and after that just go to psmi Adin and then here it is the new Option just click on new and here I'll give my database name which is multi O then click on Create and and there you can see a database is created over here and there is no table inside the database so first of all what we do is that we're going to install the this package in our L project then we are going to make some changes in the user table in order to make mtio so let's just go back to the project location and in the project location we're going to open it for so we saw here CMD then press enter Then in this cor prom we're going to run some command in order to install this in our larel project so we are going to S here composer require l/ bre minus minus dev then we press enter so it will install require Bri package in L project and there you can see it is complete so after this we need to say this common PSP rtan gra then clone in install so it will install brid right now and it will also ask you some question so here you can see which Bridge TP would you like to install is it blade liar react view or API so we are going to choose the blade on so we on here blade then press enter and do on R mode we say here no and here we're going to use the P unit so for it I'll just show it here on then press enter after that it will start installing the dependencies okay so right now again I'll just pass forward the video and there you can see it is complete so after this we need to run this command npm install and after npm install we need to S here npm run build then press enter and NP run build is also done so right now we need to run the common PSP Edition my gate but before that we need to make some changes in our code because we want to make multi so right now let's go back to our code editor I mean the subl Tex then here you can see in the project we have a database folder and inside database we have the MS folder and in the MS folder here you can see we have user table so here what we're going to do is that we're going to add one more column over here we're going to over here dollar table this Arrow sign let's over here string to first single quotation let's say it will be user type so we are going to add this column over here and the user type will have a default value and that default value will be user okay so we are going to add this column in the user table so just save it and after that you can just close this so right now what we going to do is that we are going to go back to our Command front and right now we're going to run this command HD RT Sun mate press enter and there you can see all the table is mated so right now let's just go back to our browser and here you can see in my PSM my admin if I know just refresh over here there you can see in the multi database we have some table and here you can see we have the user D so if we just go inside user D here get a name email and the user type f word here okay so right now if we just refresh our LEL project over here let me refresh and here you can see we have login and register option so right now let's go register a user if I now click on register and here let's say it will be user name then email will be user at the of g.com let's give a password over here they confirm password after that click register and there you can see we have a registered user award here so right now if we click log out it will take us to the homepage so right now let's can register on mode user and this user will be for admin so let's here admin email will be admin at of gmail.com let's give a password over here then give confirm password and after that click register and there you can see we are able to do successfully register so let's just log out again and right now if we just refresh our users table there you can see we have two user over here there you can see user of gmail.com and admin at theate of gmail.com and by default the user type is user because our here in the database migration in the user table we mention over here the default value for the user tpe will be user okay so right now what we going to do is that for the admin we are going to change the user type so here I'll just click on edit option then let me go down and for the admin we're going to S here inop user we will sort here admin then let's go down and click go and then you can see the user type change to admin so right now what we want is that when the admin login it will take that admin to the admin dashboard and with the user login it will take the user to the user dashboard okay so right now let's just go back to for editor and what we going to open here is that we're going to first create a route from the admin so that when the admin login it will call that certain route so here we're going going to say route okay before creating the route let's go and create a controller first so let me just go to the command prom again and here I'm going to say PHP AR this may Chone controller and let's say the controller name will be home controller so right now if we press enter and there you can see a controller is HED so right now let me just show you the controller if you go to app HTTP controllers and here you can see home controller so right now we need to add this home controller in our web.php so here we're going to say use app back slash HTTP back slash controllers back slash it will be home controller so we have added our controller over here so right now let's go down and create a roundout here so we going to start here route to okay to first braet to seal quation and for the ad the rout name will be admin SL let's say dashboard the out name you can give anything okay so we'll see over here admin SL dashboard then we'll give you comma word here then to third bracket we are going to mention our controll name which is home controller we saw here home controller double tone class comma we need to give a name here let's say the name will be index so right now let's save this and right now we go to the home controller and create the index function so let's go to app HTTP controller then home controller and over here we're going to say public function we're here index then to first bracket then to Second bracket over here and from here we just WR a simple view so we over here return View and the view will be let's say admin do dashboard so right now we do not have any admin. dashboard. blade. PHP in our view if you go to Resource then views there you get see there's no admin folder so right now first let's go and create a admin folder so right now I'll click on view then click new folder and here we're going to say here admin then press enter and there see we have the admin folder so in this admin folder we're going to create dashboard. blade. PHP so let me just right click over here then click new file and we're going to over here dashboard do blade. PHP contrl s then save so right now let's just here simple HTML and here in the body we're going to say and wi only for now we'll also add the log out op here so right now how do we call the this route when some user is trying to login let me just explain you a little bit about login when the user login it take the user to the dashboard and the dashboard is basically in the view Shing dashboard. bl. PP this one and welcome. bl. PHP is speciically whatever you are seeing over here okay so right now what we going to do is that instop dashboard when the user type is admin it will take the user to this r i mean to this URL and this URL will return us uh this view admin. dashboard which is this one okay so how do we do it so in order to go to this view what we need to do is that we need to go to our okay let me just show you uh step by step we need to put our app then HTTP and inside HTTP we have controllers and inside controller here you can see we have the O folder and inside o here you can see authenticated session controller.php so right now I click over here and here you can see a o is added over here and if you go down here you can see we have a function over here public function store login request request so handle and incoming authenticated request is this one okay so here what we going to do is that after the second line request session generate we're going to just add two line over here we're going to show over here if to fet Dollar request this Arrow sign we're going to mention the user tbling name into F bracket okay you this is the user table name okay so after it we we are going to give this Arrow sign and here we are going to mention this user type here you can see user type right we have user type user or admin right so we're going to mention this user type over here so we're going show here user type then we need to give triple equal three times equal give equal three times and we are going to give to sing quotation and we're to here admin then we'll give to Second bracket so here what we check is that whenever someone will try to log in it will first chck the user type if the user type is admin then we return the user return the user to the this route okay adding SL dashboard so we are going to start here return redir to first bracket s we are going to start here admin SL dashb okay so let me just explain it again so going whenever someone is trying to log in right so someone is trying to log in and when they trying to log in when they give their email and password it will check for that certain email and password it will check the user type okay so if the over here in this public store function it will check if the user typ is admin then it will call this route return redirect admin SL dashboard which is this one here you can see admin SL dashboard and if the user type is not admin then it will go about here here you can see return redirect intended route dashboard there you can see dashboard okay let me just remove the absolute false from here it will return the user to the dashboard which uh is in the also in the web there you can see you can see dashboard and this dashboard will return the view dashboard which is uh in the vi dashboard are casing this view okay so right now let's go and try to login uh so right now let me just refresh over here and here I'm going to give the admin Gmail then give the admin password over here and here you can see for the admin dashboard we have a simple just admin text over here for now we'll also add the log out option so right now if we just click on login there you can see it is to us to this URL admin SL dashboard and admin is WR over here so right now we need a log out option in order to log out for the admin so what we going to is that here if we we can just uh directly copy the dashboard. gr. pp code form here so I'll just control contrl C and we'll go to our adwin then dashboard. play. PHP over here for the admin let me just remove those paste the code and remove this s we can see what their admin dashboard okay say so right now if we refresh there you can see admin dashboard is WR over here and if you only want the log out option you can do that as well so I'm just going to remove those let's go back to the simple HTML okay here I'm going to S here again admin and we're going to have a loger option so for it what we can do is that we'll go to this layouts order so inside layout we have navigation. pl. PHP so right now I'll just directly go down and here you can see I have a form over here here you see for authentication this is from the log out option here you can see log out so I just copy this form RL C and I just paste it over here then save it and right now if I just refresh my admin dashboard there you can see I have admin return out here and I have the log out option okay I have okay I'll also remove this form here then save it and let me refresh okay so there you can see admin text and log out so right now let's go and check if the log out works or not so right now if I click on log out there you can see it took us to the homeage so right now let's try to login as a user so right now if I click on login then give the user Cain and then the password over here then click login there you can see to the user to the user dashboard so we are able to successfully log to the both admin and the user dashboard and when Adit typ to login it take the admin to the admin Dash but for the user type to log it take the user to the user dashboard but there is still one more issue over here so there you can see a user is loaded right now and if it tries to access to the admin dashboard he will be able to do if I just over here admin SL dashboard which is the admin dashboard URL link so right now if I just press enter there you can see a user is able to access to the admin dashboard and this shouldn't happen right so in order to do that that in order to protect the admin dashboard we need to use middle so how can we do it let me just show you again step by step so we need to go to our Command promp again and in order to create a midle l we need to run this command which is PSP RT sun make clone middle or and we need to give our middle or a name so normally we start with a capital letter and you can give your middle name anything you want so I'll just over here user type or I can just over here let's say admin okay so we are going to create a middle called admin so right now if you just press enter and there you go a middle is created in this location here you can see app HTP middle and admin. PHP so right now if I just go back to the code then if I now go to the add the HTTP inside HT P you can see we have a mle laer folder and inside mider we have admin. PHP so right now we're going to write a condition for our adding so here what we going to do is that we're going to write a if conditions we s on here e then we check the or if or user I mean the user table this Arrow sign we're going to mention the column name which is user ty not equal not equal andly so we give to Second graphet so right now what we doing is that in the insert that is trying to log in if his or her insert type is not admin then we will just return the user to the dashboard so we over here return redirect to the dashboard uh it means uh let me explain it again if the user type is not admin it means it must be a user right so it will send that user to the user dashboard and if the user type is admin then the request is fine okay send the user to the admin dashboard if the user type is admin and here one more thing we need to do is that here you can see we are using all a here so at the top we also need to mention that so here uh let me just copy this one crl c crl v we're going to overhead use illuminate back slash back slash support back slash fet back slash all so we are mentioning this Auto here it means we'll have the access when a user is trying to log and we'll be able to get the user type so right now we need to do one more thing and that is we need to register this admin. PHP middle R so for it here what we need to do is that uh here in our project you can see we have a boost tab folder and inside boost tab we have app.php so we need to go over here app.php and here you can see with wither function with laer dollar with lawyer so inside this let me just write it over here so inside this we need to write two line of code again so here we need to S here dollar midle or then this Arrow sign we need to se here alas like this then to first bracket and to third bracket like this and ended with a sem clone so right now inside this we need to measure middle l so let me just press enter and here we're going to mention a variable so we are going to start here admin you can name it anything but we'll just go with ADD me like this then we'll give this equal and is get than sign then we'll give this B slash then we are going to mention okay let me just show you app delacy app HTTP middle and then admin. PHP like this so after app we see over here app then HTTP then we're going to S what here middle or then B slass it will be add will we s here double clone class like this then a common and if you have more middle like admin you can just add them over here like this okay you can just add them over here like this but we only have one mdle layer over here so we are able to successfully create the middle L but again we need to do one more thing and that is we need to mention that middle for this route okay so here we're going to give this Arrow sign then we are going to S here m to first bracket and to third bracket so here first of all we'll check the on if a user is loged in and after that we will check the mdle so we will see over here admin and here you can see this admin will it come from m. PhD so here you can see admin so this is basically this solve okay so just sa but let just exate again whenever someone is trying to log in and if there is any M admin then what it will do is that it will first check the user type if the user type is not admin it means user then it will send the user to the dashboard and if the user type is admin then it will say that okay the request is f go whever you want okay and we are just over here just the admin mdle and that's all okay so you must give this mle or admin about here so right now let's save it and right now uh let me just go back if you refresh and here in Cas a user is roed so right now if a user try to go to the admin dashboard if the user Ser here admin SL dashboard and press enter there you can see it will keep the user to the same yes and over here in the admin. PHP if you just here dashboard if you just here slash it means it will send the user to the homepage so let me just show you if I just say again over here slash admin slash dashboard then press enter there you can see it to the user to the home base okay so if you want you can also create a mle for the user uh so that the admin cannot access to the user dashboard and you can also create mle for let's say uh you have one more user like manager you can then create a mle for manager as well so this is how you can make mul in LEL using bra and if you're interested how you can make three kind of user and make them log in then you can check the video on the screen where I showed you that how we can log to let's say user admin and the manager dashboard three type of user so this is all for this tutorial make sure to subscribe and I hope to see you in the future tutorials
Info
Channel: Web Tech Knowledge
Views: 15,537
Rating: undefined out of 5
Keywords: laravel multiple authentication, laravel authentication, laravel multi auth, laravel authentication tutorial, auth system in laravel, multiauth in laravel, laravel auth, auth in laravel, laravel multi role authentication, jetstream laravel, multiple role based authentication in laravel, laravel admin and user login, laravel authenticaion, laravel 11, multi auth in laravel 11, laravel breeze, how to make multi auth in laravel 11, create multi authentication in laravel 11
Id: G3UeClZPR4k
Channel Id: undefined
Length: 27min 12sec (1632 seconds)
Published: Tue Mar 19 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.