Laravel 8 E-Commerce - Admin and User Authentication

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome back to the laravel ap commerce tutorial in this video we are going to learn about creating admin and user authentication so let's see how can we create admin and user authentication in this e-commerce project so first of all let's install the data stream package so switch to the command prompt and for installing the data stream package just type here the command composer a space required all right now press enter all right now instead uh let's install the jet stream livewire package so for that just write here the command php our listen string colon install let's face livewire all right now press enter all right package has been installed now switch to the project and just go inside the database directory in migration and from here just open create user table migration okay and inside this migration let's create a column here so right here dollar table and data type a string and column name user type okay i'm just going to type here you take and also set the default value so just write here default and here uh default value is usr okay usr for normal user for customer okay and here i am using adm for admin inside the comment we can write here comment and inside the comment just get here for the remember dm for admin and usr usr for user or customer all right okay now save this file now just close this and now let's migrate the migration so switch to the command prompt run the command php artisan migrate all right now press enter okay now migration complete now run the application so just write it php artisan served all right now switch to the browser and just open the php my admin select the database ability commerce tv all right you can see here the all table now switch to the project and just open the layout file so just go inside the resources directory views and layouts and from here just open uh base.blade.php file okay and inside this file let's find the login link you can see here this is the login and this is the register link now inside this file uh after after this flying just right here at the and just check here the login route for that just right here route column column as and inside this just right here the login route and just just close here okay and inside this [Music] okay if user authenticated then do this and in else part and here just inside this if user is authorized then so here the admin or user link and if user is not authenticated then so the login and register link okay so for that just to copy this link to this link from here login and register let's cut this and just paste inside this else part okay if not authenticated then show this link all right and inside this href just add here the route double curly bracket route and inside this route just right here okay and inside the resistor do same thing double curly bracket route and inside this just right here register all right okay and if user is authenticated then just copy this li this one and just paste inside this first add here the directive both user and just access the you type column you type is equal to adm means user is admin in uh here show the admin link and otherwise inside this part hence so the customer user link okay close here all right now inside this admin uh just copy this line this li and just here for the admin okay and now make some changes so just remove this and here just add my account okay and inside the parenthesis just right here just print here the username okay so just write here fourth column column user and this text is the name all right and here add a text dashboard okay also change the title anchor title and here my account all right and for this time just remove this okay now just copy this li and paste inside the spot okay this is the normal use this is for normal user or customer and this is for the admin okay now save this file and let's check this so switch to the browser and just refresh the page all right you can see here the login link and here register link okay now let's click the login and you can see here the default login page okay and if i click on register here you can see the default register page now let's register our two user okay one for the admin and one for the normal user or customer okay so let's add the admin user so it's just just right here and here human id administrate admin.com password one two three four five six seven eight and confirm password one two three four five six seven eight all right now click on register okay just log out create one more user this time normal user or customer so just right here and confirm password now click on register okay let's log out now just go go inside the phpmyadmin and here just browse the user table and inside this user table you can see here the two user first admin and second user okay normal user now inside the utype column you can see here usr value okay so let's change here the value for the admin okay in the first column so just write here for the admin let's go inside the route directly route and from here just open wave.php okay and here let's create the route for the user dashboard and admin dashboard okay this is created by default uh here i'm just going to create a group okay for the user and for the admin so for that just write here first comment this and here let's create the route for the normal user so just write here route the middleware and inside this middleware just add here this one auth colon sanctum so just copy this and paste here also copy this verified over inside the single code here all right and then just right here group okay then add a function and inside this function let's create the route for the normal user or customer okay so just adhere the comment to user customer okay and now just copy this and paste here this is for the admin all right now let's create a middle middleware for the admin so switch to the command prompt and for creating the middleware let's try to have the command php artisan make colon middleware php artisan main colon middleware space middle name middleware name let's say middleware name is admin all right now press enter okay whatever created now run the application now access to the project and just open the middle here i mean middleware so just to go inside the app directly in http middleware and from here just open auth middleware.php and inside this handle method just add here if condition if station and just add here a key you type is equal to adm in return just copy this line okay and paste here and inside the else part user is not admin adm so first of all just plus the session so just right here session and then call the plus method flash all right and after this just return on login page so just right here return and redirect on login page so click edit and now and inside this route just add here the route login okay now click this file okay now just open the controller php file so you can see here inside the http download php file and inside the route middleware group inside this area just right here just copy this line and paste here in the name of admin all right and also change that class name here so just right here middleware slash auth admin okay column column class all right now save this file now just go inside the providers and from here just open route service provider okay and here you can see here the home home property now just change here and just remove this dashboard and simply add here slash process okay now save this all right now just close this and now just go inside the vendor directory vendor this is the vendor directory and then 45 vendor laravel okay vendor vendor then laravel okay and then src and just click on action and inside this section just open a file attempt to authenticate okay and inside this file just go inside the handle method and inside this condition just add here if auth column colon user and just access the youtube column you take is equal to adm in the creator session station and here the uk inside the array you type and just add the value adm okay and also redirect so just right here return redirect route service provider and just add here home okay and inside the air safe just check here what the user you type if you type equal to usr then inside the just copy this line and paste here this change change here the ut type usb all right okay now save this file now it's done so just close this all right now let's create a component uh one for the uh user dashboard and one for the admin password okay so switch to the command prompt and for creating the livewire component just type in the command hp artisan make colon live wire space live wire name component name let's say component name is just add here the folder name admin slash component name okay just right here admin dashboard admin dashboard component all right now press enter okay completely created now let's create the component a livewire component for the user dashboard so for that just type here php annotation name user and just write here user dashboard all right now press enter okay it created now let's application so just write here php artisan serve now switch to the project and just open the admin dashboard component class file so just go inside the app http uh livewire admin and you can see here the admin dashboard component so just open this and here just add layout and inside layout just right here under a premium layout what layout file name which is okay now save this file now just open the user dashboard user dashboard complete classifier and here also add the layout layout and inside this just right here layout start base okay now save this file and just close this now just open the dashboard component to view file so just go inside the resources directory uh then views liveware admin and just open the admin dashboard component to view file and here just remove this and inside the h1 type just right here admin dashboard admin dashboard all right and inside the user dashboard component file just right here h1 is okay now save this file now let's create the route for this component so go to the web.php file just go inside the routes we have php and now this is the group for the user or customer and this is for the admin inside this admin middleware just add here what happened okay and inside the user let's create the route so just right here route it and here that user user slash dashboard okay and then user dashboard all right and just add here the component class name which is user dashboard component okay and also add here the component class file path like this and then just write here column column class okay and inside the admin create the route route gate and uri admin slash dashboard okay and just add here that admin dashboard component class okay all right now save this file and here also add the route name okay so just write here name and route name user dot dashboard admin dot dashboard all right now save this file and let's let's add this link uh inside the layout file so just go inside the resources views layouts and just open the waste dot based.php file and here inside this admin link just add here first add double curly bracket then route and inside this route let's get here admin dot dashboard okay and for the user or customer dashboard set this hrm just right here double curly bracket then row and user dot dashboard all right okay now save this file let's check this so let's go to the browser and just refresh the page okay now just click on login and let's log in with uh normal user credential normal user credentials so just write here user accredit user user.com and password one two three four five six and eight now just click on login and here you can see the user menu okay user link and here is the user dashboard okay and click on dashboard you can see here the user dashboard okay and if i want to access the admin dashboard uh so let's access the admin dashboard so for that just type here add me okay and now just press enter you can see it right here redirected on login page okay all right now just go to the home and uh now let's login with admin credentials so just add here the admin user email id and password completely for 5678 all right now just click on login and here you can see the admin link okay and if i click on dashboard here you can see the admin aspect all right now let's create the logout logout link okay so for that just go inside the base.php file layout file and inside this uh after this li just add uh here and at the class classes menu as item okay and inside this li uh [Music] and inside this href just right here route and inside this just right here log out okay and inside this side and cut it let's add here our text log out okay and one more thing before this li just create a form here form and method method is post form method is post and inside the action just right here double curly bracket route and inside this route just add here csrf okay and now inside this uh logout anchor tag just add here javascript event on click and inside this right here event dot event default and then dot close closest and inside this just add here the form tag and just call the submit method okay submit that's it closest inside this just add the form and just call the submit method all right now just copy this and just inside this user link after this li okay now save this file now let's check this so switch to the browser and just refresh the page okay here you can see the logout link and now now click on this link and okay the gate meter is not supported for this route it means javascript is not working here so all right just remove this li from here and paste before the form tag and inside this home just add your id log out as form all right and after this inside this on click method just write here document dot element by id and inside this just write here the form id which is logout form okay and also just call here the submit method submit okay now let's check this so just save this file and just refresh the page and now just click on logout okay now it's working all right you can see here the login and register page now just copy this line this line over here to here and paste inside the user link so just remove this and paste here okay now save this file now let's check for the user so just login i'm just adding the user credential user user.com password and click on login all right you can see here the user and just click on logout okay it's working so in this way you can create admin and user authentication for the e-commerce project in next video we will see how can we how can change uh this login page and register page layout okay according to our template so that's all about getting admin and user authentication so thanks for watching this video and if you still have any kind of question you can ask me in the comment box don't forget to subscribe my channel thanks for watching
Info
Channel: Surfside Media
Views: 52,205
Rating: undefined out of 5
Keywords: How, to, Program, laravel (Software), laravel, laravel v8, laravel 8, laravel project, laravel setting up, laravel v8 setting up, laravel v8.0, v8.0, laravel 8.0, laravel 8 playlist, laravel 8 tutorial, laravel tutorial, laravel 8.0 tutorial for beginners, laravel for beginners, laravel tutorial for beginners, laravel8, laravel 8 ecommerce tutorial, laravel 8 ecommerce, ecommerce project in laravel 8, laravel 8 ecommerce project, admin and user authentication, project
Id: SW5pAAFrFqQ
Channel Id: undefined
Length: 34min 31sec (2071 seconds)
Published: Wed Nov 04 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.