I was working on creating a command and wanted to get all options, so I getOptions() in my code, but it always returned an empty array.
After doing some debugging, I found out that this getOptions method is defined in the HasParameters trait and is ALWAYS an empty array; I wonder what its purpose? I couldn’t find anything about it in the documentation. Is that a Laravel thing? Or a Symfony one?
2
Answers
As you said,
getOptions
comes fromHasParameters
, and you should see thatHasParameters
is inIlluminateConsoleConcerns
namespace, so it is 100% laarvel…So, what you want to use is:
$this->options()
, it will return an array of options…When creating a command you can provide parameters:
this signature contains:
arguments: user and test= ($this->argument(‘user’) and $this->argument(‘test=’))
ex.
php artisan app:test 1 test=mail
options: force ($this->option(‘force’))
ex.
php artisan app:test 1 test=mail --force
separately, get all: $this->options() and $this->arguments()
upd. as docs says:
actually, if you creates some command just forget about those functions