I have been following along http://laravel.com/docs/5.0/commands and able to create artisan command in Laravel 5. But, how can I create artisan command and package it to packages?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
You can and should register the package commands inside a service provider using
$this->commands()
in theregister()
method:In laravel 5.6 it's very easy.
class FooCommand,
this is the serviceprovider of package. (Just need to add $this->commands() part to boot function).
Now we can call the command like this
This will echo 'foo' from command handle method. The important part is giving correct namespace of command file inside boot function of package service provider.