Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seeding database with path from code?

I've been using Laravel's migrations with the path parameter like so:

Artisan::call('migrate', array('--path' => 'path/to/my/Migrations'));

Is there anyway I can run the seed command in the same way? I have a number of seed files I want to use but I don't want to run them all at the same time.

Any advice appreciated.

Thanks

like image 969
Dan Avatar asked Jul 17 '13 13:07

Dan


2 Answers

Instead of --path you can set --class with namespace to Seeder class.

Artisan::call('db:seed', [
    '--class' => 'Namespace\Seeds\DatabaseSeeder'
]);

This works on Laravel 5.1

like image 116
gellezzz Avatar answered Oct 09 '22 04:10

gellezzz


To refresh the migrations and seed the database, this worked for me:

// Roll back all migrations and migrate them again
Artisan::call('migrate:refresh');
// Fill tables with seeds
Artisan::call('db:seed');

I had lots of seeds and the server was slow. In this case it helps to extend the maximum execution time.

// Extend maximum execution time to 3 minutes
set_time_limit(180);
Artisan::call('migrate:refresh');
Artisan::call('db:seed');
// Back to the default
set_time_limit(30);
like image 40
matthiasgiger Avatar answered Oct 09 '22 03:10

matthiasgiger