Skip to content
Advertisement

Argument time does not exist on multi argument console command

Ι made the following command in my laravel project:

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:

  php artisan store:covid19:override 20:00 52 1234 66 77

I get the following error:

  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:

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:

        $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:

        $time      = $this->argument('time');
        $store_ids = $this->argument('store_ids')

Place a space between param and : resulting this command signature:

store:covid19:override {time : Time that goverment closes the restaurants} {ids* : The list of store Ids that close on the provided time}
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement