From e2cf7d41993d07115f2555c866e134309ebfeb85 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Tue, 20 Jun 2023 10:35:51 +0300 Subject: [PATCH] Update the method, saveMap, for CompanyAPI to save a city as parent. --- app/DotsAPI/API/v2/CompanyAPI.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/DotsAPI/API/v2/CompanyAPI.php b/app/DotsAPI/API/v2/CompanyAPI.php index e193997..142922e 100644 --- a/app/DotsAPI/API/v2/CompanyAPI.php +++ b/app/DotsAPI/API/v2/CompanyAPI.php @@ -16,18 +16,21 @@ class CompanyAPI extends AbstractItemAPI } public function saveMap($companies, $city = null) { - foreach ($companies as $company) { - $uuid = $company['id']; - $name = $company['name']; - $image = $company['image'] ?? ''; - $description = $company['description'] ?? ''; + foreach ($companies as $company_json) { + $uuid = $company_json['id']; + $name = $company_json['name']; + $image = $company_json['image'] ?? ''; + $description = $company_json['description'] ?? ''; - Company::firstOrCreate([ + $company = Company::firstOrCreate([ 'uuid' => $uuid, 'name' => $name, 'image' => $image, 'description' => $description, ]); + + if($city != null) + $city->addCompanyId($company->id); } } }