Search code examples
phplaravelcommandlaravel-artisan

Laravel commands short options


I am making a custom Artisan command in Laravel and I would like to pass in options. However I am seeing that for example make:controller has option to make a resource controller with either passing in -r or --resource. My command is now defined like this:

protected $signature = 'make {name} {--flag=?}';

But when I do a -h for command help, I see only --flag as an option. I would like to give an option to also write a -f and pass in flag as well.

I tried like this

protected $signature = 'make {name} {-f=?} {--flag=?}';

but it doesn't work.


Solution

  • Taken from the Laravel Docs:

    Option Shortcuts

    To assign a shortcut when defining an option, you may specify it before the option name and use a | delimiter to separate the shortcut from the full option name:

    The following ought to work for your case:

    protected $signature = 'make {name} {--f|flag=}';