Search code examples
phplaravellaravel-seeding

What is database seeding in Laravel?


I use Laravel framework and I have recently been informed that there is something named database seeding which produces a fake dataset for our tests. Is my understanding correct?

Well that's pretty much odd. How it works? How it knows which type of data do I need in X column of database? And how it generates it?

Also, Can't I make a seed of my real dataset (something like an export)? You know, I don't know English very well, that's why I cannot understand the concept of seed in database field.


Solution

  • Usually you're using model Factories and faker to create fake data (with relations etc) for developing and testing your app.

    If you want to seed real data, just use commands to import dump. Or, if your data is something like table with countries, create seeder which inserts the real data without using faker or model factory.

    Also, you can use some package to create seeder from real data.

    You may want to read the docs on seeding.