Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Synchro's avatar

How to call artisan commands programatically with valueless options?

I'm running L10 on PHP 8.2. Artisan supports command signatures with valueless options, for example:

protected $signature = 'project:command {--quiet}';

However, I can't figure out how to call this programatically with Artisan::call(). The docs say that options should be passed in an array as the second param, but all the examples are for an option that accepts a value, however, here the option doesn't use a value, it's a simple flag.

This leads to a problem when I try to specify it as an additional parameter; the option name must be passed as an array key, but it has no value, and no matter what I set it to, I get an error like this:

Symfony\Component\Console\Exception\RuntimeException: The "--quiet" option does not accept a value.

This occurs for all of the following approaches:

Artisan::call('project:command', ['--quiet' => true]);
Artisan::call('project:command', ['--quiet' => false]);
Artisan::call('project:command', ['--quiet' => null]);
Artisan::call('project:command', ['--quiet' => '']);
Artisan::call('project:command', ['--quiet' => 0]);
Artisan::call('project:command', ['--quiet' => 1]);

How should I call an artisan command with a valueless option?

0 likes
12 replies
LaryAI's avatar
Level 58

To call an Artisan command programmatically with a valueless option such as --quiet, you should pass true as the value for the option in the array. However, since you're encountering an error, it's possible that the version of Laravel or Symfony's Console component you're using has a bug or a change in behavior.

The correct way to call a command with a valueless option is as follows:

Artisan::call('project:command', ['--quiet' => true]);

If you're getting an error with this approach, as a workaround, you can try passing the option as a string within the command itself, like so:

Artisan::call('project:command --quiet');

This will treat --quiet as a flag without a value, which is the intended behavior for valueless options.

If you continue to experience issues, ensure that you are using the latest stable version of Laravel and that there are no known bugs related to this functionality. If the problem persists, consider reporting it to the Laravel GitHub repository as a potential bug.

Thunderson's avatar

try this

use Illuminate\Support\Facades\Process;
$result = Process::run('project:command --quiet');
return $result->output();
DhPandya's avatar

@synchro

What I will suggest is that use command with the optional arguments. So you don't need to necessarily pass that arguments each time you execute the command.

protected $signature = 'project:command {--quiet?}';

and then use without argument

Artisan::call('project:command');

If you want to pass the argument then

Artisan::call('project:command',['quiet'=>'Your value']);
Synchro's avatar

@DhPandya I know I can call it without any options, the problem is that I need to call it with options! You'll also see that my question is about what to set the value to for a valueless option, pointing out that the docs only show exactly what you did, and that it fails for valueless options! The ? in the signature is not applicable, because it's an option, not an argument, and options are (strangely enough) always optional.

DhPandya's avatar

@Synchro For a better understanding what do you mean by valueless option? How you're assuming it different in the context of the options in arguments.

JussiMannisto's avatar

As Lary said, both of these will work:

Artisan::call('project:command', ['--quiet' => true]);
Artisan::call('project:command --quiet');

I know you said you tried the first one, but it definitely should work. The only possible issue I see is that the --quiet option is already defined for all Artisan commands. Redefining it in the signature might cause issues.

Synchro's avatar

@JussiMannisto The command I'm calling is actually telescope:prune from the Laravel Telescope package, so I'm not defining my own signature at all, yet I'm still getting this error with it set to ['--quiet' => true], which is what I'd guessed it should be.

JussiMannisto's avatar

@Synchro I tested telescope:prune and the --quiet option worked both ways. Tested on: laravel/framework v10.33.0, laravel/telescope v4.17.2, PHP 8.2.6.

Synchro's avatar

@JussiMannisto Thanks for trying it. I have made the assumption that the semantics of the scheduler are the same as for calling artisan commands directly, which might have been a mistake in oversimplifying my question. The actual line of code that's triggering the error is:

$schedule->command('telescope:prune', ['--quiet' => true])->daily();

I'm pretty sure it should be the same as calling it with Artisan::call() (I would fully expect it to be using that behind the scenes anyway, and not reimplementing something), but it just might not be, due to a bug.

alanreed's avatar

@JussiMannisto Correct. This is the right way to do it.

As a note to anyone else, you can also do this, if needed:

$schedule->command('app:my-command', ['--quiet', '--other-param-with-value' => 'something'])->daily();

Please or to participate in this conversation.