data(); foreach ($data as $value) { SubDistrict::create([ 'district_id' => $this->getDistrictId($value['district']), 'code' => $value['code'], 'name' => $value['name'], 'postal_code' => $value['postal_code'], ]); } } public function data() { $villages = file_get_contents(dirname(__FILE__, 1) . '/village.json'); return json_decode($villages, true); } function getDistrictId($areacode) { $province = District::where('code', $areacode)->first(); return $province->id; } }