Laravel 5 Load Seed Data from JSON

This is very useful for seeding your tables using Laravel 5 with custom data. If you want fast population look at something to do it for you like Faker for PHP. But if you want more control on the data here is how I do it. Create a ‘/database/data’ folder and put your JSON data files in there. Then simply use the same naming schema from your JSON to match your migrations. Finally, in the seeder map the data to JSON object attributes. Below is a basic example of seeding some users.


Example users.json

Now update the seeder to grab the contents of the JSON file and create the users.

Example UserTableSeeder.php

Example Migrations File.

Sam Deering is a web developer from England (currently living in Australia). In his spare time he enjoys coding, playing chess, reading and investing.

One thought on “Laravel 5 Load Seed Data from JSON

Leave a Reply

Your email address will not be published. Required fields are marked *