Seeding our database

Remember that, in the last chapter, we already created the Bike seed, so now we just need to create another three seeds, which are going to be Builders, Items, and Garage.

  1. Open your Terminal window and type the following command:
php artisan make:seeder BuildersTableSeeder
  1. Add the following code to the app/database/seeds/BuildersTableSeeder.php public function run():
DB::table('builders')->delete();$json = File::get("database/data-sample/builders.json");$data = json_decode($json);foreach ($data as $obj) {    Builder::create(array(        'id' => $obj->id,        'name' => $obj->name,        'description' => $obj->description,        'location' => $obj->location    ));}
  1. Still in your Terminal window, type the following command:
php artisan make:seeder ...

Get Hands-On Full Stack Web Development with Angular 6 and Laravel 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.