Laravel 5 - Creating Artisan Command for Packages

user1995781 picture user1995781 · Feb 13, 2015 · Viewed 8.9k times · Source

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?

Answer

lukasgeiter picture lukasgeiter · Feb 13, 2015

You can and should register the package commands inside a service provider using $this->commands() in the register() method:

namespace Vendor\Package;

class MyServiceProvider extends ServiceProvider {

    protected $commands = [
        'Vendor\Package\Commands\MyCommand',
        'Vendor\Package\Commands\FooCommand',
        'Vendor\Package\Commands\BarCommand',
    ];

    public function register(){
        $this->commands($this->commands);
    }
}