How To Make Multiple Authentication in Laravel 11 Jetstream | 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 we can make multiple authentication in larabel using J so multiple authentication means we let both user and admin login from the same login page but the user and Adin will go to different dashboard okay and I'm going to show you everything step by step from the very beginning so right now let's go and create a fa star project so I just go to my folder and let's say We'll create project over here so for it we need to open a Comm prompt so I'll show about here CMD then press enter so it will open a common PR so right now in create our LEL project we need to run this common composer create project l/ larel and after it we need to give our project name so you can give any name you want let's say my project name will be my project you can give any name so right now if I press enter it will start creating our larel Pro and the project name will be my project so it will take some time so right now I'll just first for the video and there you can see the project creation is complete so right now we can just close this and there you can see we have a folder over here called my project and this is our LEL project so let's go and run our project so in order to run our project let's just go inside our project and here we're going to open a command PR so we here CMD then press enter so there you can can see currently we are in the POS directory so we just need to S over here bsp or this serve and then press enter and there you can see so right now we need to copy this so I'll just copy this then I'll go to my browser then if we paste it here then press enter there you can see this our facated parab project so right now we are going to install j in our L project and then we'll make some changes in the code so that we can make multiple authentication so for it let's go back to our project directory again so here you can see currently we're in the project directory and we are going to open another command Pro in the project directory so we are going to S over here again at the top CMD then press enter so it will open another common prom in the project directory and here we're going to say composer require LEL slj stream and then press enter so this will install j in our LEL project so this way Tak some time so right now I'll just first for the video and here you can see just installation is complete so right now we are going to install liveware in our project so for it we need to S here BP RT CH stream then we'll give a clone over here then we're going to S here install Live Wire and then press enter so this command will will install liver in our Lan project so right now I'll just pass for the video so here it will ask that new database migration or added would you like to rerun your migration so over here we're going to say no and then press enter so right now we're going to run this Comm npl install and after npm install we're going to S here npm run build then press enter and there you can see npm run B is done so right now we need to run the command P parition migrate but before that we need to set up our database and also we need to make some changes in the table code as well so first of all let me just open the project using Su text so I'll click on file then open folder we'll go to new volume air and over here you can see a folder over here called my project so I'll select it then select folder so right now we'll just directly go to our project. EnV file so we'll go to our EnV file and if we go down here you can see the DB connection is SQL light so in instead of SQL light we're going to show over here my SQL and inop larabel let's say here the database name will be mycore project so let me just save this and let me just copy this and let me just also go to the config folder then inside config I have database. PHP so right now let me just go down and here you can see my SQL and here you can see database DV database so here you can see laravel so in LEL we're going to see over here mycore project which we just sa over here okay so after this we can just close both of them and right now what I'm going to do is that we're going to open with sam power here so let me just start both Apache and myf over here and right now let's go to our browser we go to our TMI admin so here you can see PSM admin so right now we're going to create our database which is called uh mycore project this all so for it here you can see the new option I'll click on new then here you can see database name so here I'll give my database name which is myor Project then click on Create and there get see database is created over here and the database name is myor project and there's not table in the database so right now before we run the command pation myet in the common PR we'll make some changes in the database table migration file so here in the project here get the database folder and inside database you have the migs folder and inside Mig folder here you can see we have user table so let's go inside user table so here after the email we are going to add a column called user type so here we're going to set allar table this Arrow sign which our here string to F bracket to single quotation and let's say the column name will be user type and this column will have a default value so we saw here default and the default value will be user okay so right now let me just save this then let me close it over here and let's go to our Command prom then we're going to S what here PHP ran migrate and then press enter and there you can see a few table is migrated so right now if we just refresh our database table about here here you can see for my project we have some table over here and here you can see the user table and here you can see name email and user type so right now if I just refresh my L project we see over here login and register option so right now let's click on register and let's register the user so we're going to S here let's say name will be us user email will be user atg.com let's give a password over here then confirm password and click on register there you can see we are able to successfully register over here and if we now go to our database and refresh here here you can see name user email user at.com and the user type is user so right now let me just log out from here and let me register one more user and this one will be for admin so I'm goinging to S here admin email will be admin atom gmail.com and we are going to give a password over here then confirm password cck on register and there you can see to our dashboard and if we now refresh our database table there you can see we have one more user called adwin and the user type is by default user because we mention over here in the mation file that the default value for the user type will be user so right now what we going to do is that we're going to change the user type for the end me so for it we can just click over here and we can just show here add wi like this okay and there you can see that user type is admin or you can also just click over here get the edit option by clicking the edit option you can also change the user like okay so right now what we'll do is that when the user login it will take user to this dashboard but when the admin loging it will take the admin to different dashboard okay so for it we are going to create a route so let's go to our routes then web. PHP and before we create a route let me just create a controller first so here I going to say PHP artison make clone controller and the controller name will be let's say home controller controller and then press enter and there you can see controller is created so right now if you go to a then hn and controller here you can see home controller. PHP okay so right now what we going to do is that in the routes web.php we are going to add the controller here so for it we need to S on here use app back slash HTTP back slash controller X SL it will be home controller so here we added the home controller so it means we'll have access to the home controller from the web. BP so right now okay let me just show you one thing uh let me just loging from from here and keep the user email and password click login and there you can see that it f us to a dashboard and youas SL dashboard over here and right now if I just uh go to Resource then views inside views and you can see dashboard. blade. PHP and whatever you are seeing over here is coming from here from dashboard. blade. PHP so what we going to do is that we're going to changee this URL form here so for it what we need to do is that let's go back to our code and we'll go to our config folder here you can see config and inside config here you can see py. HP so right now if we go down here you can see p call to/ dashboard so instead of Slash dashboard let's say home equal to slash home so right now let just save this then after it what we do is that in the web.php we are going to write a route for this slash F so here we're going to say route double clone K to first bracket to s/b then we'll give a comma then to third bracket then we're going to S here home controller double clone class Comm Mark index and after it let's set this so right now we are going to create an index function in the home controller so right now what will happen is that whenever someone will try to log in it will call the slome not dashboard route it will call the slome which is this route okay so right now let's go to our home controller and create this function so we'll go to add in HTTP then controller and here you can home controller so over here we are going to say public function index then to first bracket then to Second bracket so from here what we're going to do is that we're going to check the user type if the user type is user then we'll send the user to the dashboard and if the user type is admin we'll send the user to different dashboard okay so in order to check the user type we need to add the user model at the top of our home controller so we're going to S here use add back slash models back slash user and we need to use one more thing in order to check the login user so for it we need to show here use illuminate back slash support back slash packet back slash all we need to write this in order to check the logged in user okay so right now what we going to do is that we're going to give a if condition if we Ser here all to double GL user we are mentioning the user t over here then to F bracket then this Arrow sign we are going to over here user type user type you only call is it user here let me just show you here we are checking that in the user table where we want to get the user type hand over here whenever someone is trying to login so if the user type is user it will call a if condition and if the user type is admin it will call other if condition so here we'll give two second brackets and here we're going to set return view return view will be here in the uh resource we have views and in the views here you can see dashboard. r. PHP so we are just going to measure about here dashboard only and if the user type is not user it means the user type is admin then we will go to the else condition so we're going to see over here return View and the view name will be let's say admin. home so right now we do not have any admin folder and also home. PHP so right now what I'm going to do is that in the views we are going to create a admin folder so I'm going to right click on views then click new folder and here I'm going to show what here admin then press enter and in the admin folder we're going to create home.php so let me just right click then click new file and here we're going to send home dot blade. phsp contrl s then save so about here let me just say out here simple HTML and in the body let's say out here admin homes let's save this okay so right now let me just explain what we are doing so over here we mention home equal to/ home it means whenever someone is time to login it will call this URL and this URL will call our this route home controller index function and our home controller index function will take that user type for a user that is timey to log in and if the user type is user it will send the user to the dashboard which is this song and if the user type is not user it means admin then it will send the user to this view which is admin.com which is this one only admin. Home Des here okay so right now let's go back to our browser then let me refresh and let me just log out from here let's click login and let's try to log to the user dashboard first we'll give the user user email then the user password over here click login okay we have the error over here and the UR in SL home that's fine but we have a error and I will just spelling over here it will be support like this let me just save it again then let me refresh and there you can see it took us to the user dashboard so right now if log out but before that here you can see that our URL name is/ it means it called our this URL okay so right now let me just log out and let's try to log in as a admin so let's click login and here if we say adwin aj.com then keep the password over here click login and there you can see the URL is slome and here it is s over here admin P but there you can see there is no log out option over here for the admin to log out so let me just add the log out option so for it let me just go back to the code and we'll go to our let's say dashboard. gr. PHP we can just copy the code from here contrl a contrl c and we'll paste it for admin over here you can see this is for admin view uh let me just remove this this and we can just s over here admin dashboard save then refresh there you can see it is here Adin dashboard and we have the log out option and if you only on the log out option you can do that as well okay let me just look the code from here we s here HTML let's s what here admin phone and we're going to have the only log out option and in order to do that we'll go to here you can see navigation menu. blade. PHP so here in the navigation menu. blade. PHP let me just go a l down and uh here you can see over here at this line I have a form here for log out so let me just copy this and I'll past it over here after adding home and here you can see X drop down link so I'll just remove this and here I'm just going to S over here input type it will be submit and here I'm going to say hello it will be log out and let's also remove this x data from here so let me just save this and let's go back to our browser Let me refresh and there you can see home and log out button if I click on log out there you can see to gos to the home page so this how you can make m in LEL J team so right now there is on more thing that you should do and that is you should make middle for admin so that uh the pages admin will have in the future the user should not have access to the space so you should create middle for admin but right now the user W be able to have access to the page because both user and admin use the same URL which is hold if you have different URL for admin then you should protect the admin route by creating middle so this is all for this tutorial make sure to subscribe and if you want to know how to create mid in larabel you can check out the video on the screen so thank you very much for watching and I hope to see you in the future tutorials
Info
Channel: Web Tech Knowledge
Views: 1,548
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, how to make multi auth in laravel 11, create multi authentication in laravel 11, laravel jetstream
Id: yX6G_hYAaCg
Channel Id: undefined
Length: 20min 22sec (1222 seconds)
Published: Fri Mar 22 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.