You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
972 B
37 lines
972 B
<?php
|
|
|
|
namespace App\DotsAPI\API\v2;
|
|
|
|
use App\DotsAPI\API\v2\AbstractItemAPI;
|
|
use App\Models\Company;
|
|
|
|
class CompanyAPI extends AbstractItemAPI
|
|
{
|
|
public function getMap($city_uuid = null) {
|
|
$endpoint = '/api/v2/cities/' . $city_uuid . '/companies/';
|
|
|
|
$companiesMap = $this->fetcher->get($endpoint);
|
|
|
|
return $companiesMap;
|
|
}
|
|
|
|
public function saveMap($companies, $city = null) {
|
|
foreach ($companies as $company_json) {
|
|
$uuid = $company_json['id'];
|
|
$name = $company_json['name'];
|
|
$image = $company_json['image'] ?? '';
|
|
$description = $company_json['description'] ?? '';
|
|
|
|
$company = Company::firstOrCreate([
|
|
'uuid' => $uuid,
|
|
'name' => $name,
|
|
'image' => $image,
|
|
'description' => $description,
|
|
]);
|
|
|
|
if($city != null)
|
|
$city->addCompanyId($company->id);
|
|
}
|
|
}
|
|
}
|