A few different ways to seed databases in Laravel

preview_player
Показать описание
If you want to automate adding data into your Laravel application, seeding is the way to go! Whether it's for testing purposes or adding in loads of production details, Laravel's seeders and factories help to rapidly fill up your database tables.

In this video I'll show you a few different ways to seed data into your database. We'll start out simple with just single models and the create method, and move up to custom factories and seeder classes.

- 0:00 Getting Started
- 0:31 Seeding Single Models
- 1:38 Using Factories
- 6:49 Seeder Classes
- 9:48 Seeding Model Relationships
- 12:50 Wrapping Up

Рекомендации по теме
Комментарии
Автор

Thank you, really great video for understanding database seeder and factories

abdulbasitsalah
Автор

Another trick: if you have taxonomies, pre-built categories or any special things you want to seed into your database when you start a new project, you can read from a JSON file then run a foreach loop in a seeder. You can also verify for the existence of the model rows before actually create it. Useful for seeding countries, languages, topics or some other stuff like that.

richardtrudel
Автор

Thank you very much, this was helpful

tukurhamid
Автор

Thanks for that video, man! Maybe good for a follow-up video: seeding 10 users and then for each user ... random 1 through 5 comments. $users = (all 10 users)->each->closure->(using extra variables)

nielsdrost
Автор

Yeeey.. No more conditionals or loops ... thanks

constantine