Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel custom command argument with dash

I got a custom command in Laravel 5, that gets username and password.

One user got his password starting with a dash, something like -819830219', making laravel return a error saying "The -8 option does not exist.

I tried setting the password between quotation marks and still got the same error.

Is there a way to pass a parameter that starts with a dash that laravel will not understand as a option?

protected function getArguments()
{
    return [
        ['username', InputArgument::REQUIRED, 'Partner\'s username.'],
        ['password', InputArgument::REQUIRED, 'Partner\'s password.'],
        ['origin', InputArgument::REQUIRED, 'Partner\'s origin code.'],
    ];
}
like image 332
Paulo Manrique Avatar asked Mar 13 '23 06:03

Paulo Manrique


1 Answers

You can escape the - character by prepending it with -- like:

php artisan command -- -819830219

Or you can use an interactive command like this:

public function handle()
{
    $username = $this->ask('Enter username');
    $password = $this->secret('Enter password');
    $origin = $this->ask('Enter origin');
    $this->doSomething($username, $password, $origin);
}
like image 107
Björn Avatar answered Mar 24 '23 04:03

Björn