Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 392
user151841 Avatar asked Mar 20 '16 21:03

user151841


1 Answers

I needed to use option(), not argument().

$number = $this->option('number');
like image 54
user151841 Avatar answered Nov 12 '22 16:11

user151841