Answer the question
In order to leave comments, you need to log in
Is it correct to enter data directly from migrations?
For example, I create a table with roles and I immediately need to add several roles there. Or I add a new role to a table already filled with some data. Create posts directly from migrations? In this case, the migrations become too large. What is the best way to do this?
Answer the question
In order to leave comments, you need to log in
There is no clear answer here. But in general, you can follow the following logic:
- if this is test data, then do it in seeds;
- if this is real data for the application to work, then either in migrations, or write a console command that will enter this data. Similar to seeds, but already within the application, with checks of different conditions (the current environment, for example).
My last two projects are porting applications from WordPress to Laravel and I created console commands and import mechanisms from csv / xml, and filled in small amounts of role types in migrations.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question