Laravel 5 - Creating Artisan Command for Packages

后端 未结 2 1307
刺人心
刺人心 2021-02-05 09:42

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 package

2条回答
  •  广开言路
    2021-02-05 10:25

    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).

    commands([
                \Vendor\Package\Commands\FooCommand ::class,
            ]);
        }
    }
    

    Now we can call the command like this

    php artisan foo:method

    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.

提交回复
热议问题