fix code resources
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Modules\Linksehat\Transformers\Hospital;
|
||||
|
||||
use App\Models\PractitionerRole;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class HospitalResource extends JsonResource
|
||||
@@ -14,13 +15,33 @@ class HospitalResource extends JsonResource
|
||||
*/
|
||||
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,
|
||||
'distance' => $this->distance ? ($this->distance < 1 ? round($this->distance * 1000, 2) . " m" : round($this->distance, 2) . " km") : 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'),
|
||||
|
||||
Reference in New Issue
Block a user