Ι made the following command in my laravel project:
JavaScript
x
namespace AppConsoleCommands;
use IlluminateConsoleCommand;
class Covid19CloseTimeOverride extends Command
{
protected $signature = 'store:covid19:override {time: Time that goverment closes the restaurants} {ids*: The list of store Ids that close on the provided time} ';
protected $description = "Overrides store's close times if measures against Covid19 are applied on a specific area";
public function handle()
{
$time = $this->argument('time');
$store_ids = $this->argument('store_ids');
dump($time,$store_ids);
}
}
And once I run the following command in console:
JavaScript
php artisan store:covid19:override 20:00 52 1234 66 77
I get the following error:
JavaScript
Too many arguments, expected arguments "command" "time: Time that goverment closes the restaurants" "store_ids*: The list of store Ids that close on the provided time".
Do you know why I get the error and how I can fix it?
Advertisement
Answer
The problem is your signature.
The current signature is:
JavaScript
store:covid19:override {time: Time that goverment closes the restaurants} {ids*: The list of store Ids that close on the provided time}
Meaning your parameters are:
time: Time that goverment closes the restaurants
ids*: The list of store Ids that close on the provided time
So in order to be accessible you should fetch them using the following argument
calls:
JavaScript
$time=$this->argument('time: Time that goverment closes the restaurants');
$store_ids=$this->argument('ids*: The list of store Ids that close on the provided time');
And YES it is kinda PITA therefore in order your previous code to work:
JavaScript
$time = $this->argument('time');
$store_ids = $this->argument('store_ids')
Place a space
between param and :
resulting this command signature:
JavaScript
store:covid19:override {time : Time that goverment closes the restaurants} {ids* : The list of store Ids that close on the provided time}