Add Doctor Organization Filter
This commit is contained in:
@@ -19,19 +19,27 @@ class DoctorController extends Controller
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$hospitals = PractitionerRole::query()
|
||||
$doctors = PractitionerRole::query()
|
||||
->with(['practitioner.person', 'speciality', 'practitioner.metas', 'metas', 'organization'])
|
||||
->when($request->search ?? null, function($query, $search) {
|
||||
$query->whereHas('practitioner.person', function($person) use ($search) {
|
||||
$person->where('name', 'LIKE', '%'.$search.'%');
|
||||
});
|
||||
})
|
||||
->paginate(6);
|
||||
->whereHas('speciality');
|
||||
if ($request->has('hospital_id_in')) {
|
||||
$hospital_ids = explode(',', $request->hospital_id_in);
|
||||
$doctors->whereIn('organization_id', $hospital_ids);
|
||||
} else if ($request->has('hospital_id')) {
|
||||
$doctors->where('organization_id', $request->hospital_id);
|
||||
}
|
||||
|
||||
$doctors = $doctors->paginate(6);
|
||||
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Sukses mengambil data Dokter',
|
||||
'doctors' => Helper::paginateResources(PractitionerRoleToDoctorResource::collection($hospitals))
|
||||
'doctors' => Helper::paginateResources(PractitionerRoleToDoctorResource::collection($doctors))
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user