api show hospital
This commit is contained in:
@@ -28,7 +28,7 @@ class HospitalResource extends JsonResource
|
||||
'distance' => $this->distance ? ($this->distance < 1 ? round($this->distance * 1000, 2) . " m" : round($this->distance, 2) . " km") : null,
|
||||
'photos' => [
|
||||
'title' => Str::slug($this->name),
|
||||
'url' => asset('images/default-doctor-avatar.png')
|
||||
'url' => asset('images/default-hospital-image.png'),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Linksehat\Transformers\Hospitals;
|
||||
|
||||
use App\Models\PractitionerRole;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Str;
|
||||
|
||||
class HospitalResourceDetail 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'] = null;
|
||||
}
|
||||
|
||||
if (empty($this->distance)) {
|
||||
$address = $this->currentAddress->text;
|
||||
} else {
|
||||
$address = $this->currentAddress;
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'address' => $address ?? null,
|
||||
'distance' => $this->distance ? ($this->distance < 1 ? round($this->distance * 1000, 2) . " m" : round($this->distance, 2) . " km") : null,
|
||||
'photos' => [
|
||||
'title' => Str::slug($this->name),
|
||||
'url' => asset('images/default-hospital-image.png'),
|
||||
],
|
||||
'specialitys' => $specialitys
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user