I have json file in folder database\data\countries.json
and I have CountriesTableSeeder.php
I want to seed all data in countries.json into my table Country. But it occurs error Trying to get property of non-object
I have followed the step that I found, but I still got an error.
This is my model:
protected $fillable = ['country_name', 'iso_code'];
This is my seeder code:
public function run()
{
$countryJson = File::get("database/data/countries.json");
$data = json_decode($countryJson, true);
foreach ($data as $obj) {
Country::create(array(
'country_name' => $obj->name, 'iso_code' => $obj->sortname
));
}
}