Ad

How To Pass Parameters To Command With Laravel Task Scheduling

- 1 answer

As the official docs, it doesn't mention about this a lot. App\Console\Commands\PullUsersCommand.php has a signature like:

protected $signature = 'pull:users {startTime} {endTime} {minutes=10} {--flag} {--star=}';

So, how to pass the parameters to it in App\Console\Kernel.php

Ad

Answer

You could call it in App\Console\Kernel.php like this:

$schedule->command('pull:users', [
    time(),  // captured with $this->argument('startTime') in command class.
    time(),  // captured with $this->argument('endTime') in command class.
    30,      // captured with $this->argument('minutes') in command class.
    '--flag',// should be without any value, just the option name, and would be captured by $this->option('minutes').
    '--star'=>12, // would be captured by $this->option('star').
])->daily();

It should be okay with Artisan::call facade too.

Ad
source: stackoverflow.com
Ad