<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class MyCommand extends Command
{
protected $signature = 'my:command {value}';
public function handle(): void
{
$this->line($this->argument('value'));
}
}
Run:
$ php artisan my:command test_string
test_string
$ php artisan my:command -123
RED: The "-1" option does not exist.
$ php artisan my:command "-123"
RED: The "-1" option does not exist.
$ php artisan my:command '-123'
RED: The "-1" option does not exist.
$ php artisan my:command \-123
RED: The "-1" option does not exist.
$ php artisan my:command "\-123"
\-123
Expect:
$ php artisan my:command -123
-123
The reason is Symfony trusts a parameter starting with '-' as a shortcut.
Use a double dash:
php artisan my:command -- -123
Most helpful comment
Use a double dash: