52 lines
1.8 KiB
PHP
Executable File
52 lines
1.8 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\Linksehat\Transformers\Hospital;
|
|
|
|
use App\Models\PractitionerRole;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class HospitalResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
$querySpecialitys = PractitionerRole::query()
|
|
->with(['speciality'])
|
|
->where('organization_id', $this->id)
|
|
->whereNotNull('speciality_id')
|
|
->orderBy('speciality_id')
|
|
->groupBy('speciality_id')
|
|
->get(['speciality_id']);
|
|
|
|
foreach ($querySpecialitys as $indexSpeciality => $speciality) {
|
|
$specialitys[$indexSpeciality]['id'] = $speciality->speciality->id;
|
|
$specialitys[$indexSpeciality]['name'] = $speciality->speciality->name;
|
|
$specialitys[$indexSpeciality]['avatar'] = asset('images/default-specialisasi-image.png');
|
|
}
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'name' => $this->name,
|
|
'code' => $this->code,
|
|
'description' => $this->description,
|
|
'address' => $this->address ?? null,
|
|
'lat' => $this->lat,
|
|
'lng' => $this->lng,
|
|
'distance' => $this->distance ? ($this->distance < 1 ? round($this->distance * 1000, 2) . ' m' : round($this->distance, 2) . ' km') : null,
|
|
'city_name' => $this->city_name ?? null,
|
|
'rating' => rand(1, 100),
|
|
'phone' => $this->meta->phone,
|
|
'photo_url' => url('images/default-hospital-image.png'),
|
|
'photos' => [
|
|
'title' => $this->name,
|
|
'photo_url' => url('images/default-hospital-image.png'),
|
|
]
|
|
];
|
|
}
|
|
}
|