Installing Laravel 90:00
Alright, let's do it. Here's everything you need to know about Laravel 9. First, I'm going to install it. I'll do that from the command line. laravel new l9, and actually, at the time of this recording, we're about a week out from the release, so I'm going to pull in the dev version. Which is, effectively, Laravel 9. There we go, baby. Laravel 9.x. Alright, one last thing.
Installing Laravel 80:22
Laravel 9.x. Alright, one last thing. Why don't we also install a fresh copy of Laravel 8, so that when we need to, we can compare the differences between the two. laravel new l8. And if I leave off the --dev flag, again, at the time of this recording, you can see that's pulling in laravel 8.6. Okay, I think we're all set. So I will cd in there, and open this in my editor. Okay, so let's start with some small stuff, and then we'll slowly work our way up.
Creating Post Routes0:45
So I will cd in there, and open this in my editor. Okay, so let's start with some small stuff, and then we'll slowly work our way up. I'll begin by visiting my routes/web.php file. And let's imagine we're setting up some routes for blog posts. It's always blog posts. Okay, php artisan make:controller PostsController, or PostsController, whatever you want. And now we might say, when the user visits the /post endpoint, we would load the PostsController, and then an index action, right? Next, if you want to visit an existing post, we might do something along the lines of this.
Controller Route Grouping1:15
and then an index action, right? Next, if you want to visit an existing Post, we might do something along the lines of this. Basic RESTful actions. And yeah, maybe we'll do one more. If you make a POST request to the collection, then that would, of course, hit a store action. Okay, well, new in Laravel 9, if you want, is routeControllerGrouping. So for example, if I were to say routeController, and we are working with PostController in this case, we're going to group everything within it, like so. So now think of it this way. Any routes declared within this group will automatically assume PostController, which
So now think of it this way. Any routes declared within this group will automatically assume PostController, which means I can remove some of this duplication here. And now this will do exactly the same thing. And let's test it out. And you actually get a two for one, because if I run the route:list command, the output here is also new in Laravel 9. You'll see it got a nice redesign. But yeah, notice here, if you visit /posts or a specific post, those will still defer to PostController.
Comparing route:list Output2:10
But yeah, notice here, if you visit /posts or a specific post, those will still defer to PostController. However, if I open up my Laravel 8 tab, real quick, if I run the route:list command, you'll see this is what it looked like before, and this is the way it has looked for a long time. Actually, I think I worked on this many years ago. But yeah, sometimes when you're working with tables on the console, it gets kind of warped if the screen size gets changed. So I think this is a nice improvement. But yeah, of course, if we were to try controller groupings in Laravel 8, it would throw an error.
But yeah, of course, if we were to try controller groupings in Laravel 8, it would throw an error. All right, so that is your first addition to Laravel 8 in the books. To repeat, you now have access to routeControllerGrouping, and there's also been a redesign of the route:list command.
