Search code examples
phplaravellaravel-artisan

Using Artisan::call() to pass non-option arguments


In the shell I can create a database migration (for example) like so:

./artisan migrate:make --table="mytable" mymigration

Using Artisan::call() I can't work out how to pass a non-argument parameter ("mymigration" in this example). I have tried many variants of the code below:

Artisan::call('db:migrate', ['--table' => 'mytable', 'mymigration'])

Anyone got any ideas? I have been using shell_exec('./artisan ...') in the meantime but I'm not happy with the approach.


Solution

  • Before Laravel 5

    Artisan::call('db:migrate', ['' => 'mymigration', '--table' => 'mytable'])
    

    Laravel 5 onwards

    Artisan::call('db:migrate', ['argument-name-as-defined-in-signature-property-of-command' => 'mymigration', '--table' => 'mytable'])
    

    See other answers for more details.