Laravel 5 Package Scheduled Tasks

后端 未结 2 1832
[愿得一人]
[愿得一人] 2021-02-09 10:12

I\'m developing a package that has some scheduled tasks - is there way of registering / publishing them without affecting the base applications already set scheduled tasks?

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-09 10:36

    In your package service provider, do this:

    /** @var array list of commands to be registered in the service provider */
    protected $moreCommands = [
        \My\Package\CommandOne::class,
        \My\Package\CommandTwo::class,
        \My\Package\CommandThree::class,
    ];
    

    Then in your boot() method of the service provider do this:

    $this->commands($this->moreCommands);
    

    Very good question, btw. Had me searching through the Laravel API docs to find the answer, and when I found it I implemented it in one of my own packages.

提交回复
热议问题