Series Setup and Installs0:00
Hello there! In this series, we are reviewing everything new in Laravel 5.3. So, we'll start with some of the smaller stuff, some directory changes, some changes, things like that. But then, towards the end of the series, I think you're going to see some pretty cool stuff that you may not know about. So, without further ado, we're going to get started. And you'll notice that in Sublime, I've set up a project that contains two separate directories. So, you'll see in my Sublime project, we of course have one install for Laravel 5.3. But then, I'm also pulling in a separate install for Laravel 5.2. Now, keep in mind that as I'm recording this, Laravel 5.3 isn't quite out just yet. Very likely, by the time you're watching this, it will be. But for now, if I run laravel new project, that's actually going to grab me Laravel 5.2. Instead, if I do composer create-project, I can actually install the development branch of the Laravel.
Routes Folder Restructure0:43
But for now, if I run laravel new project, that's actually going to grab me Laravel 5.2. Instead, if I do composer create-project, I can actually install the development branch of the Laravel repository. And that will give me version 5.3. So, if you're working along and 5.3 is not yet, this is the command you want to run. So, I want to start by showing you some differences in the directory structure that might take you aback for a minute. But don't worry, very simple stuff. So, here I have Laravel 5.2. It looks pretty familiar, right? Your routes file is within the HTTP directory. All good. However, let's switch over to Laravel 5.3, and bam, immediately we notice a difference. Now, what's the deal? Why is routes a folder? So, before, yeah, it was an HTTP, and it sort of made sense there, right? But now, it's been moved all the way up. And actually, quite a few conversations went on about this. And the consensus was,
and it sort of made sense there, right? But now, it's been moved all the way up. And actually, quite a few conversations went on about this. And the consensus was, routes are one of the most important things to your project. And it feels a little weird that you have to go three levels deep. So, you have to go into app, then you have to go into Http. And then, with the addition of a new routes folder, that is a third level you have to dig just to edit your application's entry point in many ways. That feels kind of wrong, right? So, instead, yeah, this routes folder has been moved to a top first level citizen. And you'll notice that you have two different files in here, web.php and api.php. So, the very first thing I can tell you is, as you upgrade, you're going to do that php artisan routes:cache, right? And you'll see this is bringing up Laravel 5.2's routes.php file. But routes.php doesn't exist in Laravel 5.3. Instead,
Web vs API Routes2:17
you is, as you upgrade, you're going to do that command php routes.php, right? And you'll see this is bringing up Laravel 5.2's routes.php file. But routes.php doesn't exist in Laravel 5.3. Instead, you're going to have a routes folder and then your web version and your api version. And these will correspond to, obviously, the proper groups. So, the routes you set up for your api will not contain the web middleware group and everything that goes along with that. Let's take a look. So, here is our middleware group for web that has everything for your typical web request, like cookies and session handling and CSRF tokens and all that stuff. However, for your api, yeah, you don't necessarily need a lot of that stuff. Instead, you might want throttling and bindings. So, let's go to another file, our RouteServiceProvider. And once again, this will be in your providers folder. Anyways, if we scroll down, you'll see a change here. So, we have our web
So, let's go to another file, our RouteServiceProvider. And once again, this will be in your providers folder. Anyways, if we scroll down, you'll see a change here. So, we have our web specific routes. And notice that it automatically wraps everything within this file within a route group where we set the middleware group to web. However, for your API routes, yeah, we're not using all of those web specific middleware. Instead, we're using our API specific middleware. And you'll also see, by the way, that it does apply a prefix to anything here. So, that means, for example, if I go into api.php, and let's take a look, give you some more real estate, just a single simple route here. Okay, well, if I run php artisan route:list, yeah, you'll see we have two routes out of the box. Your traditional homepage that uses the web middleware group. But then another one with the API prefix /user that is using, once again, our API.
App Directory Simplification3:50
see we have two routes out of the box. Your traditional homepage that uses the web middleware group. But then another one with the API prefix /user that is using, once again, our API middleware. So, now you'll see, yeah, that's just going to grab the authenticated User associated with the request. So, that's one change. And really, it's a big change. Because I promise, php artisan route:list is just, it's ingrained in us, right? You're going to have to change it. Either do something like rweb, that's what I've been trying to get myself into. So, r for routes, and then web for the file I want, or r API to go to that one. Yeah, something to think about. Okay, so that takes care of routes. Next, though, you're going to see that if we go into the app directory, it's vastly more simple. I'm really happy about this change. So, just for comparison, in Laravel 5.2, your app directory has a bunch of stuff. So, notice events, and jobs, and listeners,
directory, it's vastly more simple. I'm really happy about this change. So, just for comparison, in Laravel 5.2, your app directory has a bunch of stuff. So, notice events, and jobs, and listeners, and policies. But what is going on here? Because where is events, and listeners, and policies? All of that stuff is seemingly gone, but no, it's not. So, here's the deal. If you think about it, Laravel 5.2, by default, it doesn't have any events. This is just an abstract class to get you started. You don't even need to use that if you don't want. But also, listeners, empty. Notice the .gitkeep. Policies, .gitkeep. So, they're included for you, but also, if you think about a newcomer, this can be pretty overwhelming. If you're moving up from WordPress or something, you're introduced to a lot of jargon that you likely have no familiarity with. So, in Laravel 5.3, you don't see them natively until you run the associated artisan command to create it.
On-Demand Directory Generation5:24
you're introduced to a lot of jargon that you likely have no familiarity with. So, in Laravel 5.3, you don't see them natively until you run the associated artisan command to create it. So, for example, let's say I do want a listener. So, we're going to make, and yeah, let's make a listener with an event. Okay. So, php artisan make:event, and how about, and what's one for Laracast? Maybe UserBecamePremium or something like that. You get the idea. Okay. So, now, you'll see that we do get the events directory. So, it's sort of, once again, like a just-in-time type setup. It'll only create the directory once you run the command, and that way, how many GitHub repos have you looked at where the events directory or the policies directory is completely empty, right? Well, now, that'll never be the case. If you don't create a policy, you never have to have the policies directory there, and I think it's quite a bit cleaner, especially for newcomers. So, here
Well, now, that'll never be the case. If you don't create a policy, you never have to have the policies directory there, and I think it's quite a bit cleaner, especially for newcomers. So, here is our event, and we could say make a listener for that, and how about sends, I don't know, thank you email, and the event will be User became premium. Okay. So, now, once again, you get the listeners directory on demand, and yeah, we're not going to keep doing this, but the exact same thing for any of the others, like make policy for a UserPolicy, and you'll see that show up here on demand, which is really great. Okay. So, yeah, I think that's mostly it for the directory changes. So, it may seem drastic, but it's really not at all. All these directories still exist, they're just generated on demand, and then finally, your routes folder has been upgraded to a first-class citizen, and you no longer have a routes.php file, so train yourself.
they're just generated on demand, and then finally, your routes folder has been upgraded to a first-class citizen, and you no longer have a routes.php file, so train yourself to traditionally go to your web.php file instead. All right, moving on to episode two.
