api doctor detail

This commit is contained in:
Muhammad Fajar
2022-10-27 14:37:12 +07:00
parent 0ece467d21
commit 2f84f43ae5
11 changed files with 245 additions and 106 deletions

View File

@@ -15,10 +15,16 @@ class HospitalResource extends JsonResource
*/
public function toArray($request)
{
if (empty($this->distance)) {
$address = $this->currentAddress->text;
} else {
$address = $this->currentAddress;
}
return [
'id' => $this->id,
'name' => $this->name,
'address' => $this->currentAddress->text ?? null,
'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),