Search code examples
phplaravelcommand-line-interfacelaravel-artisan

Laravel artisan command - Change option in script?


Is it possible to change options passed to a Laravel command in the PHP file? I've tried a couple things like $this->option('optionName', 'newValue'); but have not found a solution. Also, I can't simply get the value and set it to a new variable because I'm extending the migration command and need to reset the option for that. The --path option to be exact.


Solution

  • Sorry for anwsering my own question but I found a solution that will work in my case:

    $this->getDefinition()->getOption("optionName")->setDefault("newValue");

    Since its only overriding the default, it only works if the option was not passed through the CLI. if someone has a better way of handling this please provide the answer!