36 lines
957 B
PHP
36 lines
957 B
PHP
<?php
|
|
|
|
namespace Modules\Linksehat\Transformers\Dashboard;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Str;
|
|
|
|
class HospitalResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
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-doctor-avatar.png')
|
|
]
|
|
];
|
|
}
|
|
}
|