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?
I don't want to overwrite the App/Console/Kernel.php
as the base application may already have it's own scheduled tasks etc.
You certainly can, all through the power of some basic object-oriented programming!
Step 1: Create Your Package's "Kernel" Console Class
Let's create a Kernal class within your package's Console directory where we will be extending
App\Console\Kernel
.Step 2: Add the
schedule
methodSince we are extending the App Console Kernel, we'll want to add the relevant schedule method and call the parent class' implementation of it. This will ensure that any previously scheduled tasks carry through.
Step 3: Add your scheduled tasks
Now you may add your own scheduled tasks per normal.
Step 4: Register It!
We'll want to bind the class to the container, and
make
it within our package's service provider'sregister
method:That should be all that's required!
Some things to take into consideration with this though:
In your package service provider, do this:
Then in your boot() method of the service provider do this:
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.