dimanche 20 mars 2016

Can't add argument to custom command

I'm using laravel 5.1. in a debian bash shell. I created a custom console command called survey:complete. I've been using it for a while, and now I want to add an optional argument for the number of surveys to generate.

However, I've followed the documentation, but I haven't been able to successfully add my argument. I changed the signature likewise:

protected $signature = 'survey:complete {--number=}';

And tried to reference the argument

public function handle() { 
    for( $i = 0; $i < $this->argument('number'); $i++ ) { 

But I get this error:

$> php artisan survey:complete --number=1
[InvalidArgumentException]
The "number" argument does not exist.

I print_r()'d the arguments array, and I get this:

$ php artisan survey:complete --number=1
Array(
    [command] => survey:complete
)
[InvalidArgumentException]
The "number" argument does not exist.

How do I add my argument to my command?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire