Laravel 8 Authentication Tutorial with Laravel Breeze

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right welcome back to another video this video is going to be on just building a basic authentication system for your existing or new level 8 project i'm going to show you the simplest way to do it the currently correct way to do it it's gone through a lot of changes over the years but currently we use laravel breeze to just build basic authentication before i get started i'm going to go through like a sample project i just want to mention that in level 5.4 when i started using laravel we were using php artisan make auth it was a command within laravel that would generate the login register routes views controllers validation migrations everything we need basically that was then extracted for whatever reason into a package currently lives in laravel ui which you can see here now it is it is it does support level 8 but it is marked as a legacy package uh i'm not sure what happened here there was a lot of talk on twitter about it but i don't really understand i just know that the original level ui stuff or the make auth stuff was bootstrap based and i guess now it's bootstrap but also view and react with bootstrap uh if you're into this you could use it i mean i don't know how long it'll be supported but the newest almost like spiritual successor to this is laravel breeze and breeze is great so let me go through breeze breeze basically just provides everything you need for a basic authentication it's by default based on blade and tailwind css so it like uses blade components you can opt to use view view or react and that by default will force you to use inertia.js to kind of bridge the front end to with the back end we also have the option of using jet stream now if you're really looking into authentication systems jet stream is an option jetstream is more feature packed i guess you could say it builds on top of breeze in a lot of ways it you know it offers things like session management api support using something like called laravel sanctum which is a topic for a whole different video it has team management we don't need any of this stuff for this video and most people looking for basic authentication probably don't need that either and so it also offers tailwind css and inertia and live wire and it's very similar to breeze it just offers a bunch more stuff but for this video i think we're going to use breeze so let me just go ahead and create a new project here let's call it laravel new authentication demo uh truth be told i know that this is going to create a project with authentication underscore demo as the table name so i've just gone ahead and created that beforehand here once that's done installing i can just cd into it here and let me clear the terminal and now i'm just going to valet link and valet secure this is just something for my local so it looks like that's done and now if i click this link it should take me to a local laravel fresh project and it does you can see i'm running level 8.44 on php version 8.0.3 and what we want to do now is install breeze itself and so if you're looking into the documentation here there is a very simple composer command composer require level breeze as a dev dependency because we're just going to be basically publishing the assets within the the package into our project and that is now installed we can now use the command php artisan breeze install and that's already installed so we can copy this and run npm install and npm run dev this will install our npm dependencies and then run and compile the front end now this may take a while so let's start now okay it looks like that's finished up the last thing we have to do is just run migrations so php artisan migrate remember that the uh the migrations we need for authentication were published with this when we published the stuff from the package and if we go back to our database now table we see our failed jobs migrations password resets and users tables were migrated so this is where most of our attention will be focused id name email password and remember token i mean this is all you need for a basic authentication system so it is pretty cool and now if if we go back to our demo site here we can see we have a login link and a register link let's go ahead and register so i'm going to use david david test.com password password and we're logged in so you can see this breeze comes with this nice dashboard here that you can opt to use or not use it's your choice out works we can also log in so david test.com that logs us in and so let me go through the actual project and show you how this works maybe we could create a demo route that we could secure so let me clear this this will open it up in vs code for me okay and so the app looks the same i mean from the outside you can't really tell that anything's been done but if you go into the app http controllers and auth directory here you can see that there's a whole bunch of authentication related controllers that were created we just use the register user controller to register and so it's really good to just explore these when you when you install it just to get a feel for how they're written and how to kind of leverage them in your project we use the auth.register route to register and that's where the actual form is if we actually click into there you could see that like i was saying before everything is set up with blade components so it's very neat it's a really really great system and i really do like using it in my projects very easy to extend and also kind of reuse bits and pieces of once we actually submit the form and our account is being stored as an account our user is created the registered event is fired off and then our user is authenticated or logged in and we are redirected to whatever is the value of route service providers home constant so let's see what that is and we could see that the constant is set to slash dashboard and that's why we were redirected to the dashboard right after registering what is interesting about logging in is that if you're trying to access a route that's not slash dashboard and it you're not logged in once you do log in correctly it will just redirect you to wherever you are trying to go anyways so as far as i can see this is really only used for registering maybe password reset another couple interesting things here is actually in the web file as you can see our slash dashboard route is right here and it looks very simple i mean there's nothing really in here so you're i wonder to myself where's the all the authentication stuff and this is probably the one complaint i have with this compared to the old php artisan make auth system before we had something like route auth that would register all the authentication routes and i thought that that was nice and simple what's been done this time around it just requires an auth.php file if you open up this file here you'll see that all the authentication routes are here and you can modify them to whatever you want they're in the routes folder right beside web.php and you can see that the routes that are secured with the with the off middleware are the ones that will require you to log in to see them and i could demonstrate this by using just the welcome route so right now if i i'm logged in okay if i copy this and go to just the home route you could see that i can see it if i just throw the middleware on there save that i can still see it because i am logged in you can see that i'm logged in because i have the option to go to the dashboard if i log out of here and try to refresh this it'll try to force me to log in and like i was saying earlier if i log in trying to go to get to the home route and i do successfully log in it'll take me to the home route nice and easy uh if you are new to laravel and you want to kind of group these together you totally can and the way this is done is by just removing these middleware things and making a route group so route middleware off this is a little bit outside the scope of authentication but i think it is good to show so anything within within this function here any route rather we'll have the uh off middleware check done on on the route so we can definitely see that still working by logging out again here and trying again to get into this one of course we can log in like before and everything will still work so there are some other cool features password reset password confirmation you do need email to be set up to test that and the documentation does list that so you can check that out if you want but the basic gist of it is you just need level breeze to set up an authentication system i hope this video was helpful please do let me know below if you have any questions or any comments on this and once again thanks to everyone for watching i'm glad you're enjoying i think i'm going to switch a little bit to tailwind videos in the coming weeks i just want to give laravel a break so yeah thanks again and i hope to see you in the next video
Info
Channel: David Grzyb
Views: 2,808
Rating: undefined out of 5
Keywords: laravel, authentication, tutorial, breeze
Id: CWjCKSmX03Q
Channel Id: undefined
Length: 9min 41sec (581 seconds)
Published: Thu Jun 03 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.