Files
aso/Modules/Internal/Transformers/OrganizationResource.php
Linksehat Staging Server 70fc1579e7 update
2024-07-12 08:41:18 +07:00

56 lines
2.0 KiB
PHP
Executable File

<?php
namespace Modules\Internal\Transformers;
use Illuminate\Http\Resources\Json\JsonResource;
use App\Models\Corporate;
class OrganizationResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
$corporateId = $this->corporate_id_partner;
$corporateIds = explode(',', $corporateId);
$corporatePartner = '-';
if (count($corporateIds) > 0){
$corporatePartnerNames = Corporate::whereIn('id', $corporateIds)->get();
if (count($corporatePartnerNames)>0){
$corporateName = [];
foreach($corporatePartnerNames as $corporatePartnerName){
array_push($corporateName, $corporatePartnerName->name);
}
$corporatePartner = implode(', ', $corporateName);
}
}
$organization = [
'id' => $this->id,
'name' => $this->name,
'type' => $this->type,
'code' => $this->code,
'description' => $this->description,
'kodeRs' => $this->meta->KodeRS ?? null,
'phone' => $this->meta->phone ?? null,
'lat' => $this->currentAddress->lat ?? null,
'lng' => $this->currentAddress->lng ?? null,
'address' => $this->currentAddress->text ?? null,
'province_id' => $this->currentAddress->province_id ?? null,
'city_id' => $this->currentAddress->city_id ?? null,
'district_id' => $this->currentAddress->district_id ?? null,
'village_id' => $this->currentAddress->village_id ?? null,
'postal_code' => $this->currentAddress->postal_code ?? null,
'corporate_id_partner' => $this->corporate_id_partner ?? null,
'corporate_name' => $corporatePartner,
'active' => $this->status == 'active' ? 1 : 0,
];
return $organization;
}
}