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?
I needed to use option()
, not argument()
.
$number = $this->option('number');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With