Scaffolding Authentication 0:00Trust me, you will love this one. So, let's review authentication. Laravel, new. Some project. We'll start from scratch. Okay, that's ready to go. I will cd in. Next, I'll say phpArtisan, and take a look at this. Now, if we look under the make namespace, we have one called makeauth. So what this is going to do is scaffold some basic login, registration, and password resets form. And it'll also update your outs file. Okay, pretty cool. So phpArtisan makeauth. Configuring SQLite Database 0:25And it'll also update your outs file. Okay, pretty cool. So phpArtisan makeauth. And generally, it's good to do this at the beginning of your project, rather than later. Anyways, next, we don't have a database yet, right? So let's touch one. And like we've been doing, I will stick with an SQLite database. Alright, I will open this up in Sublime. And if I switch to config slash database, and if we scroll down, I will set my default connection to SQLite. And then once again, if we scroll down, the database path is already set correctly. Migrating and Running App 0:52and if we scroll down, I will set my default connection to SQLite. And then once again, if we scroll down, the database path is already set correctly. Okay, so believe it or not, we're all set to go. From scratch, we have authentication out of the box. phpArtisan migrate. Now phpArtisan serve. And yeah, take a look at what we have. We did this in what, 60 seconds, 90 seconds with explanation? So I'm going to log in. We can do anything we want. Of course, we don't have an account yet, so that won't work.So I'm going to log in. We can do anything we want. Of course, we don't have an account yet, so that won't work. We can register. John Doe, john at example.com, password, password, register. So now we have an account, and we're signed in. If we go to our little dummy dashboard page, slash home, yeah, here we go. And we can see John Doe is signed in, and of course we can log out, in which case we can no longer access that route. How cool is that? Think of the convenience this provides, where you're able to get up and running with a new idea Setting Up Mail Logging 1:48How cool is that? Think of the convenience this provides, where you're able to get up and running with a new idea basically quicker than any other possible tool you could use. Now let's say we're trying to sign in, but we can't remember our password. Okay, forget your password. John at example.com. That will then email me a link. But in this case, it's failing because we haven't set up our mail config. So let's do that now. I'm going to go to config, slash mail.So let's do that now. I'm going to go to config, slash mail. And if we scroll down, we can see the default driver is SMTP. But remember, you can always override this within your .env file. So down here, you can see this is the settings we're actually using for local development. And then when you push that up to production, you would once again create another .env file that would have your production-specific settings. That way, for example, if you're working locally, you can set the mail driver to log. But for production, you can set it up to SMTP or whatever you want. So in this case, yeah, let's change that to log.But for production, you can set it up to SMTP or whatever you want. So in this case, yeah, let's change that to log. Next, if we come back, we can set our default from address right here. And we'll say support at lericast.com. And we'll say right here, Lericast support will be our default. Okay, so let's try it again. Run it. And there we go. Now actually, a quick note on that though. If you were working along and you ran it again, but you still hit an error,Now actually, a quick note on that though. If you were working along and you ran it again, but you still hit an error, do me a favor and close your server and then run it again, and that should fix it. Okay, so anyways, we have emailed your password reset link. But in this case, we are using the log driver. So in this case, it will simply be logged to a file. You can find that within your storage directory. So if we cd in there, yeah, you can see a logs folder for any application-specific logs. Now, by default, we have a single one. So if we review that, you'll see this contains any errors that were thrown since we've been working. Using Password Reset Link 3:37Now, by default, we have a single one. So if we review that, you'll see this contains any errors that were thrown since we've been working. But in our case, we just want to go to the bottom. And right here, you can see the email. So the subject was your password reset link from Lericast support to john at example.com. And here's his message. Click here to reset your password. Okay, so I'm going to copy that, and we're going to take a look at this. I'm going to paste that in. Now, notice the format, password slash reset, and then this long little hashed key here.I'm going to paste that in. Now, notice the format, password slash reset, and then this long little hashed key here. That's a unique identifier that gets stored in the database. And once again, Leravel just does all of this for you since it is something that basically every application will require. You don't need to do it. It's good for learning purposes, of course, and I can show you how to do that at Lericast. But for production, there's no need to reinvent the wheel. So we take care of that for you. All right, so we run it, and now we can choose a new password. I'll say new pass, new pass, reset it, and there we go. Reviewing Auth Routes and Views 4:30All right, so we run it, and now we can choose a new password. I'll say new pass, new pass, reset it, and there we go. That reset my password and signed me in. So now if I log out and log in again, john, and then new pass, and there we go. We're signed in. Okay, so it's important that you note, if we switch over to our routes file, that when we ran that php artisan make colon auth command, it also added a route group section right here. So in this case, I can remove this section entirely since it is a duplicate. Yeah, notice route auth. This is a method that will automatically register all of the necessary routes for you.Yeah, notice route auth. This is a method that will automatically register all of the necessary routes for you. And if we take a look at that, we can go to our router class, and then if I look for auth, yeah, here you go. Here's all of the routes it registers for you. So your basic stuff like log in and log out, one for registering and posting to register, and then, of course, for password resets. So further, if you ever need to completely override anything, yeah, just go to app, http, controllers, auth, and you can modify these however you want. Okay, final little note here. So this gives you a good starting ground, and it uses Twitter bootstrap,Okay, final little note here. So this gives you a good starting ground, and it uses Twitter bootstrap, but very likely you will want to modify this, right? Of course you do. Go to your resources, views directory, and now notice everything that was added for you. When you ran that command, it created a layout file here where it pulls in some fonts and styles. Yeah, you can remove all of this stuff. This is just to get you started. If you don't want that, get rid of it. Now all this stuff, once again, is optimized for Twitter bootstrap since people often use that,If you don't want that, get rid of it. Now all this stuff, once again, is optimized for Twitter bootstrap since people often use that, especially when trying out new ideas. But this will give you a good example of how you might go about formatting these things. Next, for your login and registration specific pages, once again, you can see we extend the layout file, and then we add our section that contains the login form. And that's all there is to it.