Laravel 4: Deploy custom artisan command in package

后端 未结 1 1661
鱼传尺愫
鱼传尺愫 2021-02-06 13:39

I have developed some custom artisan command for easier use with my package. Is it possible to include the artisan command into the package for easier deployment? If can, how?

1条回答
  •  旧时难觅i
    2021-02-06 14:27

    Having a command set in your package structure:

    You can, in your package Service Provider:

    registerMyCommand();
    
            $this->commands('mycommand');
        }
    
        private function registerMyCommand()
        {
            $this->app['mycommand'] = $this->app->share(function($app)
            {
                return new MyCommand;
            });
        }
    
    }
    

    The trick is in the line

    $this->commands('mycommand');
    

    Which tells Laravel to add your command to the artisan list of commands available.

    0 讨论(0)
提交回复
热议问题