Moving Routes to Controller 0:00It's pretty neat that we can provide a closure to handle our routes logic. And in particular, for small projects, it's really useful, I think you're going to like it a lot. However, to be honest, for more sizable projects, you'll almost always reach for a controller instead. Let me show you how. If we were to rewrite this route, we would do it like so. We could say, still, listen for a post. But in response, I'm not going to handle it in this routes file. I'm going to load a controller. Naming Controller and Method 0:25But in response, I'm not going to handle it in this routes file. I'm going to load a controller. Now if we're dealing with blog posts here, you might call it postController or potentially postController. Either one works and both are very common in the Laravel community. I typically do plural, but I'm not a stickler for it either way. Okay. So we're loading a controller here, but now we need a method on that controller. Now we'll talk about this more in the future, but for the time being, if we are showing a blog post, maybe we should call that method show.Now we'll talk about this more in the future, but for the time being, if we are showing a blog post, maybe we should call that method show. And as you'll learn more in future episodes, that's a common convention. Okay. So I'm going to comment this out or delete it entirely. And if I were to switch back to Firefox and give this a reload, it's going to blow up. That's because our controller does not exist. Now you can create this in two ways. One, from the sidebar, you could open up your app, HTTP, controllers, and you can create a new one here. Creating Controller Manually 1:15One, from the sidebar, you could open up your app, HTTP, controllers, and you can create a new one here. So we'll do that together very quickly. And if I switch back, give it a reload, now the error will change. It's saying, okay, I found that controller, but there is no method called show, so I don't know what you want me to do. All right. Let's create that now. Show. And once again, we'll just return hello.Show. And once again, we'll just return hello. So if I come back and refresh, now we've successfully routed to a controller. Which means if I paste in what we had earlier from the previous episode, I can now remove the routing declaration. But don't forget, it accepts a post. The same will be true for your controller method. Okay. So let's get rid of that. And this is what we end up with. Generating Controller with Artisan 2:01So let's get rid of that. And this is what we end up with. So if I switch back to Firefox, give it a reload, it works just like it did in the previous episode. So that would be one way to create the controller. However, we could also use a generator. Let me show you. Let's delete this file, and we'll start from scratch. And if I switch to the terminal, I can run php artisan, and you're going to see lots of commands here.And if I switch to the terminal, I can run php artisan, and you're going to see lots of commands here. It can be a little overwhelming at first, but remember, you'll learn these one at a time when and if you need to. So anyways, if we scroll up, you'll see this big namespace section for make. All of these will generate files. A controller, a command, an event, a model, a job. All of these you'll learn about. So one of those is called make-controller. So let's do it again.So one of those is called make-controller. So let's do it again. I want a post controller. There we go. We have our controller. So if I paste in that method from earlier, and we get the exact same thing.