fix resources hospital
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace Modules\Linksehat\Transformers\Hospital;
|
||||
|
||||
use App\Models\PractitionerRole;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Modules\Linksehat\Transformers\Speciality\SpecialityForHospitalDetailResource;
|
||||
|
||||
class HospitalResource extends JsonResource
|
||||
{
|
||||
@@ -15,20 +15,6 @@ 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,
|
||||
@@ -45,7 +31,10 @@ class HospitalResource extends JsonResource
|
||||
'photos' => [
|
||||
'title' => $this->name,
|
||||
'photo_url' => url('images/default-hospital-image.png'),
|
||||
]
|
||||
],
|
||||
$this->mergeWhen($this->specialities, [
|
||||
'specialities' => SpecialityForHospitalDetailResource::collection($this->specialities)
|
||||
])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Linksehat\Transformers\Hospital;
|
||||
|
||||
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'] = asset('images/default-specialisasi-image.png');
|
||||
}
|
||||
|
||||
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
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Linksehat\Transformers\Speciality;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SpecialityForHospitalDetailResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => 'Spesialis ' . $this->name,
|
||||
'avatar' => url('images/default-hospital-image.png'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ class SpecialityResource extends JsonResource
|
||||
'specialis' => 'Spesialis ' . (isset($this->speciality->name) ? $this->speciality->name : $this->speciality_name),
|
||||
'experience' => rand(5, 12),
|
||||
'rating' => rand(20, 100),
|
||||
'price' => Helper::currencyIdrFormat($prices) ?? null,
|
||||
'price' => $prices ? Helper::currencyIdrFormat($prices) : null,
|
||||
]),
|
||||
$this->mergeWhen($this->name, [
|
||||
'title' => 'Spesialis ' . $this->name,
|
||||
|
||||
Reference in New Issue
Block a user