Passing Arguments to Laravel's Artisan::call method


Committed to the LaraBrain by: wjgilmore (@wjgilmore) at February 8, 2016 4:41 pm

Pass arguments to Artisan::call is possible but the proper approach is not obvious

When executing automated tests I occasionally want to insert a custom set of data using a specific seed file. You can execute the various Artisan commands inside a test using the Artisan::call method. For instance to import all of your configured seed files you can call db:seed like so:


However, if you want to pass additional arguments into an Artisan command you'll need to identify them as a key-value pair inside an array, like so:

Artisan::call('db:seed', ['--class' => 'App\\TestSeeder']);