fix resources code
This commit is contained in:
@@ -9,6 +9,7 @@ use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Linksehat\Transformers\Hospital\HospitalResource;
|
||||
|
||||
class HospitalController extends Controller
|
||||
@@ -19,7 +20,7 @@ class HospitalController extends Controller
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
/**$hospitals = Organization::query()
|
||||
$hospitals = Organization::query()
|
||||
->with(['currentAddress'])
|
||||
->where('organizations.type', 'hospital')
|
||||
->when($request->search ?? null, function ($query, $search) {
|
||||
@@ -32,7 +33,6 @@ class HospitalController extends Controller
|
||||
});
|
||||
$hospitals->select([
|
||||
"organizations.*",
|
||||
// DB::raw("ST_Distance_Sphere(point(addresses.lng,addresses.lat), point(".$request->lng.",".$request->lat.")) /1000 as distance_km"),
|
||||
DB::raw("6371 * acos (cos ( radians($request->lat) ) * cos( radians( addresses.lat ) ) * cos( radians( addresses.lng ) - radians($request->lng) ) + sin ( radians($request->lat) ) * sin( radians( addresses.lat ) )) as distance_km")
|
||||
]);
|
||||
|
||||
@@ -42,7 +42,7 @@ class HospitalController extends Controller
|
||||
}
|
||||
|
||||
if ($request->has('order_by')) {
|
||||
switch($request->order_by) {
|
||||
switch ($request->order_by) {
|
||||
case 'distance_asc':
|
||||
if ($request->order_by == 'distance_asc' && $request->has('lat') && !empty($request->lat) && $request->has('lng') && !empty($request->lng)) {
|
||||
$hospitals->orderBy('distance_km', 'asc');
|
||||
@@ -53,7 +53,7 @@ class HospitalController extends Controller
|
||||
$hospitals->orderBy('distance_km', 'desc');
|
||||
break;
|
||||
}
|
||||
default:
|
||||
default:
|
||||
$hospitals->orderBy('organizations.name', 'asc');
|
||||
break;
|
||||
}
|
||||
@@ -65,13 +65,11 @@ class HospitalController extends Controller
|
||||
}
|
||||
|
||||
$hospitals = $hospitals->paginate($limit);
|
||||
// dd($hospitals->toArray());
|
||||
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Sukses mengambil data Rumah Sakit',
|
||||
'hospitals' => Helper::paginateResources(HospitalResource::collection($hospitals))
|
||||
]);*/
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user