Seeding database with path from code?

霸气de小男生 提交于 2019-12-04 11:20:28

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

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

This work on Laravel 5.1

Seeding only

Artisan::call('db:seed');

Re-run all migration under specified path & run seeds as well

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

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!