Laravel seeds after migration

Is there anything I can contribute to my migrations to automatically populate the table with test data after the migration is complete?

Or do you need to sow separately?

+6
source share
2 answers

You can call migrate:refresh with the --seed to automatically seed after the migration is complete:

 php artisan migrate:refresh --seed 

This will result in rollback and restart of all your migrations and subsequent launch of all seeders.


As a little more, you can also always use Artisan::call() to run the artisan command from the application:

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

or

 Artisan::call('db:seed', array('--class' => 'YourSeederClass')); 

if you need a specific seeder class.

+26
source

While lukasgeiter's answer is correct, I would like to elaborate on your second question.

Or do you need to sow separately?

Yes. Since you are talking about test data, you should avoid linking inoculation with migration. Of course, if this is not test data, but application data, you can always insert data into the migration part.

As an aside, if you want to sow your data as part of testing , you can call $this->seed() from your Laravel Test Test.

+3
source

Source: https://habr.com/ru/post/982345/


All Articles