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.
- Open your Terminal window and type the following command:
php artisan make:seeder BuildersTableSeeder
- 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 ));}
- Still in your Terminal window, type the following command:
php artisan make:seeder ...