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

GuruBob picture GuruBob · Oct 2, 2014 · Viewed 28.4k times · Source

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.

Answer

Bower picture Bower · Oct 2, 2014

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

Incidentally db:migrate isn't an artisan command out of the box. Are you sure this is correct?