Admin & User Multi Login System using Laravel Breeze | Laravel Blog Project Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone in this tutorial I am going to show you how you can make admin and user multi-authentication in laravel breeze so here you can see this is just a first day created larabelle project so first of all we will install Breeze in our laravel project so for it let me just go to the project directory and here in the project directory I'll open a command prompt let me just zoom in and here in order to install this we need to write this command which is composer require lot of help slash Breeze then if we press enter it will install brace in our laravel project so it will take like one minute to install Bridge so here you can see the package is installed so after writing the command composer required laravel slash Breeze we need to write this command which is PHP Artisan Breeze clone install and from here we need to choose which one we want to use we will choose our hair blade for blade we need to write over here 0 then we'll press enter then it will ask us would you like to use dark mode support we will say no no then press enter and here uh it will ask would you prefer paste test instead of PSP unit will say no over here again and then it will install some dependencies so after that we need to server here npm install then we'll say npm run build so right now after npm run Bill we need to migrate our table in our database but before that we need to make some changes in the migration table so for it let's go open our project over here you can see this is the project and here first of all we directly go to the database folder then migration folder and inside migration you can see over here we have user table over here so in order to make multi auth we need to have a user type in the user table so here let me just copy one thing from here and after password list paste it over here and we are going to show over here user type and by default the value of the user type will be user and if the user is admin then the value will be admins but normally whenever someone registered their default value for the user type will be user so right now we can just save this and we can run the command PSP Edition my gate so let's go to our Command Prompt again and here we are going to say PHP Artisan migrate press enter and here you can see some table is migrated so right now if we just go to our database and here if you just refresh over here here you can see some table is migrated in the project and if you go to user table you can see we have name email password and here you can see user type and one more thing since we installed this so it will automatically make the login and registration option over here so right now if we refresh here here you can see we have the login and paste option so let's register to user in the table so let's click register and let's over here user gmail.com let's give a password over here and the confirm password click register and here you can see you are currently the dashboard so let's log out again and let's restart onboard account and here we are going to say admin then email will be admin at that of gmail.com let's give the password then confirm password again click register and here we are logged in so right now every time it is taking us to the dashboard so let's just log out from here and right now if we just refresh our database table over here you can see we have two user honest user at data gmail.com and another one is admin here you can see and here you can see the user type for admin is user so what we are going to do is that we are going to modify this user type for admin to admin so if I just double click over here we can just modify it over here or you can just click over here edit then go down and change the user type to admin for admin this username okay then we just click over here go so here you can see the user type is admin for adminator gmail.com so right now what we want is that when you are trying to login using user then it will take us to the normal dashboard but when we are trying to login with that with this email here you can see that user type is admin so it will take us to the admin dashboard so that's what we want so let's go to our code editor and here first of all let me just make it small and first of all we'll just directly go to app then provide us here you can see inside app we have providers and inside providers we have route service provider so right now if you go down here you can see public const home dashboard and let me just show you the route page over here we will go to Route then web.php so whenever we are trying to log in it will automatically call this dashboard URL and this dashboard URL will call this route get dashboard and it will then take the user to the dashboard page after login so we are going to modify this from slash dashboard to slash home let's save this and right now we are going to write a route for this slash home so let's go to our web.php and here we are going to say route our clone gate to files bracket single quotation slash home then we'll give you come over here to third bracket and we need to mention a controller name let's just server here home controller for now controller double clone class comma let's see the function name for in the controller will be index so right now let's just set this and first let's go and create a home controller so let's go to a command prompt and we are going to server here PHP artisan make controller home controller so home counter is created as you can see so right now if you go to app then http then controller here you can see home controller so let's go to home controller and restart your function over here public function index file bracket and to Second product so right now first of all since we are trying to logged in from the user table so we need to make sure that we add the user table model over here so we'll show over here use app backslash models backslash user and then we also need to add the okay I keep the on P Capital so here we are going to say okay let me just copy this use illuminate backslash support backslash packets backslash auth so right now we'll have the access to the user and the auth in this home controller so over here what we are going to do is that we will first write the if condition if we say auth double clone ID so here first of all whenever right now what will happen is that whenever someone is trying to login it will call the Home slash home URL from here and our slash home URL will send us to this home controller index function which is this one so over here first of all we'll check if there is any auth ID so if there is an auth ID we will check the user type if the user type is user then we'll send the user to the user dashboard and if the user type is admin then we'll send the user to the admin page okay so here we are going to declare variable let's say what here dollar user type equal to auth double flash bracket then user to first bracket this Arrow sign and we just get the user type so far we will get this user type we will get this user type from the database table from here either you will get user or admin so here right now we give another if condition we say if dollar user type equal if the user type is user then we'll send the user to a certain page return View and inside the season view we mention over here dashboard and normally when we login we normally go to the dashboard.blade.php which we can see in the resource Hues here you can see dashboard.plate.php save this over here and in the web.php it is register the home controller so here we are going to say use app backslash HTTP backslash controllers backslash home controller so after adding the home controller whenever we are trying to login if the user type is user then it will send the user to the dashboard which is this on this uh this is the view that we normally get from here for this route so we'll just basically call the same view from here we'll change it later but let me just write the else condition over here else if we give to first bracket okay let me just copy this and we'll paste it here like this okay so here first of all for the first one if the user type is user send it to the dashboard and for the second one if the user type is admin then we will send the user to a different view let's say over here okay let me just first create a folder in the view so let's create a folder over here I'll just right click on The View then new folder let's say folder name will be admin and inside this admin folder let's create a new file and let's over here admin home dot play dot PHP let's just save it save and inside this we are just going to have a normal HTML and in the body let's say h on admin page let's just say this for now let's save this and let's go to our home controller and here we will mention the folder name we chose admin and here you can see admin and the file name is admin home so here we'll say admin dot admin home so after this and if the user type is not user or admin then we'll just go to the else condition and in this else condition we'll just over here return redirect it will be back let's just set this so right now if the user type is user then it is industrial dashboard and if the user type is admin it will send us to the admin dot admin homepage so basically let me just explain it again whenever someone is trying to login it will call the Home URL our home URL will call this slash home URL and this slash URL will call the index function in the home controller so whenever we will login we will see Slash home after the login for both user and for both admin so let me just save this and let's refresh our browser over here and let's just first try to go to the user dashboard let's say over here user and let's give the user password click login and here you can start URL slash home and we are currently in the user dashboard so let's just log out from here and let's try to go to the admin page so here we'll say admin then we'll give the admin password click login and here you can see we are in the admin base and the URL is also slash on so we won't be able to go to the user home page whenever we are admin or user so let's just add a logout option for the admin page so for it what we'll do is that we will go back to our code and we'll just directly go to all dashboard.blade.php and let me just copy this and we'll just paste it in the adminhome.play.php so control a control V and we are going to server here let's just say admin dashboard and you are logged in as admin so let's save this and let's just refresh here and here you can see admin dashboard you are logged in as admin okay so right now let me just show you a issue over here so let me just remove that slash home and let's go to this space and right now if I just over here you can see you have the dashboard option over here and if I click dashboard even though we are admin it is not saying over here admin dashboard or you are logged in admin so for it what we'll do is that let me just go to the code and we'll just actually go to Resource views then layouts and inside layouts we have navigation.plate.php over here you can see there's a few route mentioned over here for dashboard so what we are going to do is that we are going to modify that route name from dashboard to slash home so let me just copy this Ctrl C Ctrl f and here if I press enter here you can see it will show us on by on so here install route dashboard we are going to server here home stop dashboard so it would not have to modify this because this is not a route just a text so let's just go down there is three more so this one this one so here we are going to say home is there any any more oh no that's not so let's just save it and since we are saying route home so in the web.php we need to uh mentioned over here name name home okay let's save this and we will also remove this dashboard option from here or we can just comment this out that's fine as well so right now let's just go back and let's just go to the first page over here you can see the dashboard text and if I click dashboard okay it's still calling the dashboard because over here you can see this is the welcome base so let me just go to the welcome.blade.php and let's just search dashboard here so you can see our dashboard so instead of dashboard will say home let's save then let's refresh here let's click dashboard and here you can see it will always take the admin to the admin dashboard and user to the user dashboard so right now let me just show you one more thing and that is uh we better use a middleware for our login controller so here you can see middleware auth we can just copy it or just before the name we can just keep this Arrow sign and we'll say here medial wire and inside this we are going to say auth okay let me just show you like this I think you see it a little better after the index we'll give this Arrow sign will say medira auth then name so right now if we save this everything should or properly and let's just try to log into the user dashboard user let's give the password login so this is the user dashboard there is nothing over here so right now one more thing that I would like to do is that uh we will create a middle word for the admin so that not any unauthorized user can log into the admin page so here we are going to say PHP artisan make clone medial or admin w a r d not I okay press enter and it created Middle Earth so right now what we'll do is that we'll go to our code then we'll go to app HTTP and inside HTTP you will see a middleware folder and in inside middleware you can see admin.php so here uh over here we'll just write a if condition inside this public function handle we'll say if auth user this Arrow sign and we will say user type equally call admin if the user type is equal equal admin then the request is okay so we'll show our hair request next request if the user type is not admin will abroad it so who is our hair ab work let's say photo on or on means an unauthorized access I think so let's save this and again we need to register this Middle Earth in the kernel dot PHP so where is the candle.php you need to go to app HTTP and inside HTTP here you can see kernel.php so here let me just go down and at the after email verified we'll mention a variable let's say admin equal to first we need to give a backslash then we'll say app backslash HTTP backslash media lawyer backslash admin which will start middle word that we just created and after it we'll show our hair double clone class so we can just save this so we just create a middleware for admin so whenever we do not want any user to access any page we can just use this admin modular to not let the user access that page so let me just show you the example over here because in the future tutorial we will use the admin meteor so that's why I want to show you this so it's over here raw wood Tower clone get then let's say we have a URL called post comma and let's say home controller double clone class comma let's say function name will you post as well so right now let's go to our home controller and create a post function so we'll go to our home controller and let's create a function list over here public function post and we'll just see it in a simple view we'll say return View Place just over here post so let's save this so right now let's go down and inside the views let's create a file let's say post Dot blade dot HP let's save this and inside it we are going to say let's say HR admin post page so right now if you just write in the URL slash post will have access to the post.blade.php will be able to see that so let me just go to browser okay unexpected okay in the candle the reason is uh I the mistake is I already know that is we need to give a is greater than sign over here let's save this so it will not give us an error right now let's refresh okay we are kindly in the user we are logged in as a user and if you just say over here first we will be able to see this space admin post space so right now if we do not want to let the user access this space so what he can do is that in the web.php hover here we'll just mention the needle wire then we give two parts bracket then to third bracket and let me just write it like this to third bracket and first we'll say auth the ease one must be logged in then we will also see over here the user must be admin so basically we will call the middleware admin PHP will come over here and check if the user type is admin okay the request is fine otherwise it will show us either that unauthorized access or something which is this on Airport so right now here you can see that you are already we are already a user as logged in as a user and right now if we just change the url to post and press enter here you can see it is showing us error 41 and authorized so let's go back and let's try to logged in as the admin so let's click login let's over here admin keep the password click login okay we are currently logged in as a admin and right now if we see over here slash post will have be able to see that page here you can see admin postview so I'm just showing you this for a just for example because in the future we'll be using the admin middleware for some pages so I am just showing the example so I'll just delete the post.plate.ph from here because I am just trying to show you example and I'll also remove this public function post from here and from the web.php as well but we'll do similar things like this in the future tutorial so this was all so admin middleware is basically necessary for multi-authentication because there are obviously some pages that you don't want normal user to have access so this is all about this multi authead integration in laravel press for user and admin I hope you learned something new I tried to make this tutorial as simple as possible and beginner friendly but if you still facing problem or if you have any question you can always let me know in the comment section and you can even suggest me some videos that you want me to make so if you want more video like this then make sure to subscribe I'll upload more learnable project in the future thanks in for watching and I'll see you in the future tutorial
Info
Channel: Web Tech Knowledge
Views: 44,455
Rating: undefined out of 5
Keywords: laravel auth, laravel multi auth with breeze, multi auth with breeze, laravel multi auth, laravel multi authentication, laravel breeze multi auth, multi auth in laravel, laravel multi auth admin and user, laravel auth admin and user, laravel user and admin auth, laravel multiple authentication, laravel multi role authentication, login laravel, laravel auth api, laravel api authentication, http basic authentication, basic authentication, http digest authentication
Id: veBSb9JiKTA
Channel Id: undefined
Length: 22min 27sec (1347 seconds)
Published: Fri Apr 14 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.