Generating Artisan Commands0:00
Alright, check this out. We know that we can generate a new Artisan command by doing php artisan make:command and then whatever it is that your command happens to be. Now one that I have is for indexing Algolia. So that will read all of the lessons at Laracasts, create an index, push it up to their servers. So let's go ahead and run that. Now here's the new thing in Laravel 5.5. In the past, you would have to visit your command file, declare your signature, and then switch over to the kernel and register it. Not a big deal.
Auto-Registering Commands0:28
then switch over to the Kernel and register it. Not a big deal. However, take a look. If I run php artisan right now, and we look for the default name, there it is. So command name is coming, if we go back, this is the default signature you get. So what this tells us is that in Laravel 5.5, your artisan commands are automatically registered. So now let's just change this to maybe Laracast index Algolia. So now let's filter down all the commands to just the Laracast ones, or the ones that have a Laracast namespace. And sure enough, there we go.
Kernel Command Loading1:28
But yeah, if we run it, that's all going to be the same. The new thing in Laravel 5.5, once again, is that you no longer have to switch over to your Kernel and manually register the commands. And you can see right here, this is new in 5.5. So we're calling a load method, and we're passing a path to your commands directory. So if you want to take a look at that real quick, console kernel load, yeah, here it is. So this is all it's doing. So it's using Symfony's finder component. It's looking within the commands directory.
How Auto-Loading Works1:54
So it's using Symfony's finder component. It's looking within the commands directory. For each one, it just does some basic string replace to turn the file path into your namespaced path. And then it resolves the command. Such a little addition, but it does make the whole process a lot more seamless. I like it.
