Commands
Creating commands
All created commands should be stored in the console/commands directory.
Also, all created commands must be registered in the command config, which is located in the console/configs/ directory.
Example
Let's look at an example of creating a command that will display the first argument passed to it.
First, you need to create a class in the console/commands directory that will be responsible for executing the command.
namespace Console\Commands;
use Console\Support\Console\Response;
class HelloWorldCommand
{
public function __construct(array $Command)
{
print_r($Command['Arguments'][0]);
}
// The help method will be called
// if the help argument is passed to the command.
public function help()
{
Response::InfoWithExit(
'This command displays the first argument passed to it.'
);
}
}
Here, the Help method uses the InfoWithExit method of the Response class. More information about interacting with the console can be found here.
Next, for the command to work, it must be registered in the command config in the console/configs/ directory.
use Console\Commands\HelloWorldCommand;
return [
[
'Name' => 'HelloWorld', //Console command name
'Class' => HelloWorldCommand::class //Command Class
]
];
Now, to test the newly created command, enter our command into the console:
php nailer HelloWorld "Hello World!"
This will output "Hello World!" to the console.
Command list
make:controller
This command will create a new template for your controller in the app/controllers directory.
php nailer make:controller HomeController
make:model
This command will create a new template for your model in the app/models directory.
php nailer make:model User
make:middleware
This command will create a new template for your middleware in the app/middlewares directory.
php nailer make:middleware Auth
serve
This command will start a local server on your computer.
php nailer serve