Skip to content
Advertisement

Call php artisan custom:command with an argument at the end without specifying the ones before

Is there any way that if I have a command of this kind:

protected $signature = 'custom:command {arg1} {arg2} {arg3?} {arg4?} {arg5?}';

To call it without specifying arg4, but with arg5? Something like:

php artisan custom:command arg1_val arg2_val arg3_val arg5_val

Of course, if I do it like above arg5_val will be interpreted like arg4_val and arg5 will be ignored.

I hope my question is clear and it was not answered already. Did not even have a clue how to search for it :))

Thanks in advance!

Advertisement

Answer

You can use optional arguments

// Optional argument...
custom:command {arg5?}

.. but they need to be at the end. Otherwise the command does not know if an argument is left out.

Another way is to use options. Then you can specify these with option_name=option_value

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement