Rolling out your own Artisan commands
At this stage you might be thinking about writing your own bespoke commands. As you will see, this is surprisingly easy to do with Artisan. If you have used Symfony's Console component, you will be pleased to know that an Artisan command is simply an extension of it with a slightly more expressive syntax. This means the various helpers will prompt for input, show a progress bar, or format a table, are all available from within Artisan.
The command that we are going to write depends on the application we built in Chapter 3, Your First Application. It will allow you to export all cat records present in the database as a CSV with or without a header line. If no output file is specified, the command will simply dump all records onto the screen in a formatted table.
Creating the command
There are only two required steps to create a command. Firstly, you need to create the command itself, and then you need to register it manually.
We can make use of the following...