I have a command that takes in a number of days as an option. I did not see anywhere in the scheduler docs how to pass in options. Is it possible to pass options in to the command scheduler?
Here is my command with a days option:
php artisan users:daysInactiveInvitation --days=30
Scheduled it would be:
$schedule->command('users:daysInactiveInvitation')->daily();
Preferably I could pass in the option something along the lines of:
$schedule->command('users:daysInactiveInvitation')->daily()->options(['days'=>30]);
You could also try this as an alternative:
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Mail;
class WeeklySchemeofWorkSender extends Command
{
protected $signature = 'WeeklySchemeofWorkSender:sender {email} {name}';
public function handle()
{
$email = $this->argument('email');
$name = $this->argument('name');
Mail::send([],[],function($message) use($email,$name) {
$message->to($email)->subject('You have a reminder')->setBody('hi ' . $name . ', Remember to submit your work my friend!');
});
}
}
And in your Kernel.php
protected function schedule(Schedule $schedule)
{
/** Run a loop here to retrieve values for name and email **/
$name = 'Dio';
$email = '[email protected]';
/** pass the variables as an array **/
$schedule->command('WeeklySchemeofWorkSender:sender',[$email,$name])
->everyMinute();
}
You can just supply them in the command()
function. The string given is literally just run through artisan as you would normally run a command in the terminal yourself.
$schedule->command('users:daysInactiveInvitation --days=30')->daily();
See https://github.com/laravel/framework/blob/5.0/src/Illuminate/Console/Scheduling/Schedule.php#L36
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With