Laravel Admin And User Login ~ Laravel 10 Multi Auth System ~ Separate Login For User and Admin

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone today in this video we're going to build multiple authentication system using laravel 10. in this system they're going to be separate login page for both admin and user admin will able to login using their login panel and user will able to login using their login panel both are separated and for admin we are just going to create only the login system not the decision system because it's not necessary to create decision system for admin right but for user you will get both login and recession system but if you want to keep resume system in admin panel 2 you can just simply follow the video today and you will able to do that too so don't worry about it at all okay now let me give you a little overview of the full project so this is the project and if we just go to slash login it will take us to user login page and if you go to the slash admin slash login it will take you to the admin login page from this page you will able to login to your admin panel if you are admin and from this page you will able to log into your user panel if you are a user now let me show you I can simply provide my user email and password here to login to my user panel okay it's successfully login and if I go here and still if I refresh the admin login page it is staying because with the user details you will not able to use the admin panel so if you want to access the admin panel then you have to provide here admin Gmail adminator.gmail.com and then password going to be what I provide here just click on login and it will take us to admin dashboard here you see so both are separated completely if you log in using user details and using the user login page then it will take you to the user dashboard and if you log in using the admin login page it will directly locked you and redirect you to the admin dashboard page so it's awesome right and when you are login if you try to access the login page you will not able to do that because all is protected all right my friend now let's jump into it before starting this video I request you guys to please hit the Subscribe button and if you need a step by step blog post for this one and also the code simply go to this URL you will find this your link in the description or into the comment section and click on this and it will that will take you to my blog where you get step by step every code and every instruction what you need to do in order to build one multiple authentication system using laravel so multivore authentication system is very important for any project you want to build using laravel because that's how you separate and secure admin panel and user panel right so yeah let's do it and let's follow the step very fast step is we have to create a fresh laravel project if we don't have yet so for that you can simply copy this code composite create project and then your project name then where you want to build just go there I'm just going to build it here so I'm just going to open here my CMD command prompt and type here composer create create project laravel slash laravel and then project name I mean I'm just going to type here project auth okay that's it and what is going to be happening right now it will immediately start it to download everything we need to start a laravel project right it will take few seconds but sometime it may take longer because of your internet connection it completely depends on that by the way my friend uh what is the next step next step is after installing the laravel our next step is installing the VIS authentication system yes for user panel we're going to use the base authentication system and then we're going to Simply copy the authentication system and key create a guard admin guard and use that in our admin panel as well so it's going to be super secure and easy to do let me show you I'm going to show you everything one by one don't worry at all okay so it's just successfully install our laravel you can see it installs successfully now let's run it for running it we have to type here CD and then our project name Project Earth so it will find out the project directory then we can just run here PHP artisan serve and boom it's done and you here you see it's a fresh project no login distribution system yet now let's build that in order to build that we can simply uh you can simply go to this okay just open another tab in the CMD and type CD and the project project directory and simply locate it and then let's install the bridge to install the base first of all you have to write composer require laravel Breeze dentist date you can simply go to our blog and copy it if you want to okay everything is here all you need to just copy and paste and follow the instruction and watch the video carefully okay so everything going to be perfect next one is bsp Artisan please install blade I'm going to use the blade templating that's why if you use view or react then that's a separate process whoever you're watching this video try to do whatever I am doing by following me and then next time you try by yourself okay and if you successfully done that Simply Save the code and use letter in any of your projects so you don't have to do the same thing over and over again so yeah our Breeze installed successfully next we have to run PSP Artisan migrate but before that let's create our database so go to our PSP my admin click on Neo and type your project or simply click on create okay and then what then simply we have to open our project into our vs code so code dot it will open it into vs code okay after it happened into vs code just go to the dot EnV folder and here you will able to provide your database information to connect it with database so our database name is Project author just provided here our DB username is root and there's no password by default and PSP admin so we we also don't have any password so let's save it and next next just follow the steps next step is we can now run this phpi Artisan migrate so simply go here and type PHP Artisan migrate and it will migrate all the table and then run npm install Okay and then lastly Run npm Run Deep nbm Run Deep so every code is available here so just go and copy if you want to next one is step three step three is we have to create a model and migration for admin now before doing that just refresh our project you will see now login and registration system is available and these login and registration system we are going to use for the user okay so now let's create one user account so that you will able to see that how it working for user let me give here the name RC wood and for email is going to be user rate of gmail.com for password I'm going to provide one random eight digit password and then click on register that should be okay yeah our account is successfully created you can see here rc4 and this is our user dashboard so user system is successfully done now the hard part which is we have to build one authentication system you for our admin panel right so there's nothing available for our admin column right now so let's do it so step three create model and migration for admin so you have to create a model and migration for our admin to do so we have to we have to create another command from tab so just copy the project directory from here open a new command prompt CD that and it's located successfully next we can run this so to create a model and migration you can just simply run this PHP artisan make model and then the model name going to be admin you can give any name you want but admin is perfect here so I'm just going to give you an admin and dash M for creating the migration file so just copy it or just simply click here to copy and that's it and simply go to your command prompt and paste that PSP Edition make model admin then Dash M that will create a model and migration for us next step is go to your admin migration file and add this to your table okay so just go to your project in Visual Studio code then go to database then go to migration and here you will see a table called create admin table migration open this and inside this you have to provide all this field okay and it will create one ID one name email email verified add password and token table actually one table with all this field in our database so just copy them simply go here and paste it here like this so that's it so it will create a admin table with all of this field okay now next step step 5 is go to our admin model file and replace code widget so simply go simply close it and then go to app model admin model file and here you see this is your admin model file copy the code from here just like this go back to the admin model and paste the code which you just copied okay so that's to simplify the process I provided the code for you it's just make your work easier that's all now next one is Step six also add this protected guard name to your admin model so you have to add this protected guard equal to admin to our admin model so I have to add simply go to your admin.php and after EOS hash API token hash Factory and notificable just paste it like this protected guard equal to admin now we have to create this create this card okay so to create this card where we have to go you can see to do so go to config folder and inside that you will find or dot PSP okay inside the config folder let me show you inside the config folder you find this or the Facebook okay after going here you see already one card available called Web so just copy this one simply like this copy this one and paste it and change the name to web to admin and the provider going to be here admins okay and then scroll down a bit you can see here the provider okay this is the step um fixo as well and just copy this provider user okay and paste it like this and change this to our admins provider which we just created here you can see you can see admins provider now change the model directory or path to app slash models admin right in our in our model folder we have a model called admin.php just located here successfully okay done after that after that we are good to go to the next step next step is Step 7 now run the migration for adding admin table to our database if you go to our database right now uh our database name is Project auth you can see here user table available but there's no admin table if you will run the migrate right now PSP Artisan migrate then it will migrate the admin stable also to our database you can just go to our database right now refresh you can see one admin table already created in our database so it's step 7 and now step 8 is go to inside HTTP folder then controller copy the auth folder all file from there next inside controller folder create another folder called admin auth and paste all the copied file to it okay so yeah let's do it simply go to app HTTP controller auth and copy all the file from here like this and then inside of the controller folder create another folder called admin or and inside of this admin auth paste all the file you just copied okay next work is simply change the name space of all admin auth file so go to adminot files like authenticated session controller and all the files are available and since the name space right now the name is changed because we change the folder for them so it's going to be admin auth because in it is right now instead of this app HTTP controller and admin auth folder right so just copy this one and replace it in all the file you just copy and paste okay simply like that nothing else just change the name space for all the file all the file inside of this admin auth folder okay okay I am not going to keep this register user controller because for admin panel we don't need decision system but if you want you can keep it's completely up to you okay okay now awesome Next Step next step is Step 9 now open the authenticated session controller for file okay you can just go to app HTTP controller admin auth folder and inside of this you can find this authenticated session controller okay so next what who is this inside of our admin folder okay this file is responsible for login user okay in this file you have you will get the code of when we access the login doubt we what view to display function that responsible for login and record okay let me show you guys in this file you get the first function who is display the base or view um in which you get the login from by using which letter you will going to login and this is the function who is actually locked you in and this is the function who is actually locked you out okay now we have to make some changes here first of all we have to change the gate function view to admin auth login okay so just simply go to this file again you can see it is right now returning path Dot Login we're going to add here admin dot or login now we have to create this right because we don't have this view file you know to create that you just have to go to Resource view you can see here already auth folder right so just copy it and instead of the view folder create another folder called admin and instead of this admin folder the space the or folder that's it okay that's it next we also have to change the route service provider to admin dashboard okay so again if you go to this file you will see in the store function we have a route service provider that means after login in which route it will redirect your user it is by default is home for user login so we're just going to replace it with our admin dashboard okay with our admin dashboard simple like this now we don't have this um variable in our route service provider so we have to create this in our route service provider how to do that simply click on this route service provider so it will open or you search simply go to app HTTP provider okay app app then provider you can see app.provider and instead of this you will find route service provider and in soft service provider we have the public cons home just copy this and paste it once and now just copy your admin dashboard from here and replace it with admin dashboard and it will actually direct user to admin slash dashboard okay slash admin slash dashboard so after user login successfully using admin detail they will able to directly relate to admin dashboard okay so the URL you're providing here it will be responsible for your admin login redirection okay so this step is done you can see you can find Details here next we have to create a view for this okay we have to create this view to do so go to your view folder create one admin folder they are copy your previous author okay we already did that lastly here in authenticated session controller file in the destroy method change all guard to admin which is web now way so when you logged out it logged out the admin okay so all other thing is done simply you have to do is we have to go to authenticator session controller in the destroy function we see it is right now log out the guard way but when it's logging out the admin it should log out the admin not the way so just replace it with admin so that's it fine now step 10 now go to the request folder okay copy and paste the full auth folder change the name to adminot okay now we have to go to the request folder where you get the request folder you can see app HTTP and here the request folder copy the full auth folder okay copy and paste now change the name to admin auth what admin auth awesome then what then open the inside file name login request okay in admin auth we have the login request file and change the name space okay change the name space right now it is inside adminode folder so we have to change the name space and then what and change the name accordingly and next in authenticate function at the same file at the guard admin okay simply just copy this authenticate function fully you will get the code here and go to that file which you just change the name space and locate the authenticate function this is the authenticate function just replace it like this because we add here one guard called auth guard admin then other thing which will help us to login as admin guard okay now go to your authenticate session controller file again and change the app HTTP request auth login or to use app HTTP request admin auth login request okay so again go to your authenticated session controller and here you can see app HTTP request auth login request change it to admin auth okay because for admin login request file is located in request folder and inside there we have the admi note folder which is just created right awesome thank you okay now Step 11 go to web PSP okay in route folder and create the admin dashboard route mentioned below okay just copy it and then go to where routes then of.psp and inside of this just paste the thing you just copy okay or just to wheel of this user's copy paste whatever you copied okay and then also require this one required dir minole.psp okay like this like this you have to require this also sorry just copy this one copy this one paste it like this and change its name to admin auth okay now we don't have this file we have this auth.php but we don't have admin.php we have to create this in the route folder so in the route folder just create admin auth dot PSP now why are you going to get the code for this one simply follow this instruction or just copy this code from here and come back to this file paste everything save it okay okay now step 11 is done now instead 12 now go to your view folder inside the admin folder open the auth folder open login View and inside the view change the route for the action okay okay so now we have to go to the resource okay let me let me minimize all the file okay resource View admin auth and in the login.blade.php we have to change the route and this route going to be what this route going to be right now admin Dot Login okay admin Dot Login so where we create this route there should be a question right now to in your mind if you just follow the step 12 or 11 profile you already see that we just create admin or the PSP file and inside of this you will get that here you can see admin had been login route here you can see admin login route admin login route okay so this is it now this is perfect for our login and if you want to keep the registration as well then go to the decision and also change the route for that as well also for confirm password forget password reset password and verify email do the same thing okay okay awesome now we Step 13 we don't have the admin dashboard View let's just get it now okay so to create that we have to go to the Vu admin folder and inside of this admin folder right now I'm going to create a blade file called dashboard dot blade dot PHP and right now I'm just going to provide here one is to tag with desktop admin dashboard later we can create a layout for this and to Simply load a full dashboard template here it's completely known to you right it's nothing new okay now step 14 now go to your HTTP folder then go inside the middleware folder open redirect it if authenticated file and inside that handle function you will see a Forest Loop and in the forest loop at this code okay fire okay go to app http middleware then redirect if authenticated and inside of this for this Loop the space the code you copy and this will help the guard admin login to admin dashboard after they successfully login okay now a time to test the full system okay we already see the login system for user now try for the admin admitted access admin dashboard it will not work so admin then login you will see that's the admin login panel but we don't have one admin yet to create one admin you can simply go to your database in the admins table you can create one okay just simply let me create one by inserting our admin name going to be admin and the email going to be admin at the rate of gmail.com and password hash I'm going to copy from here simply okay paste it like this okay done so we already get one admin now we can just log in with that admin at the rate of gmail.com password going to be the provided password and login and you can see it is related as to our admin dashboard if anyone not logged in as admin and try to access it it will create them to their user login press not in admin login so that's the system that's the process everything is done try it and if you find it hard just follow the full post once pause the video carefully once or twice it is a bit hard for the beginner but for that reason I provided the code so you can just simply simply follow it nothing nothing going to be hard okay so yeah that's it for today's video thank you so much watch this carefully build it in next we are going to use this authentication system anywhere we create any project in our laravel tutorial okay so that's it again thank you bye
Info
Channel: ASIBUR
Views: 14,106
Rating: undefined out of 5
Keywords: laravel 10 multi auth system, how to build admin login system in laravel 10, build separate login system for admin and user using laravel 10, laravel 10 authentication, laravel 10 admin and user login, laravel admin user, laravel admin and user login, laravel admin user authentication, laravel admin user management, laravel auth admin, laravel auth admin and user, admin auth laravel 10, laravel authentication user and admin, laravel user and admin auth, laravel multi auth guard
Id: LiMT6vFtcmU
Channel Id: undefined
Length: 30min 17sec (1817 seconds)
Published: Thu Jul 20 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.