This commit is contained in:
2025-06-16 15:58:34 +08:00
parent cfb277e446
commit 3870b38c56
+15 -10
View File
@@ -58,18 +58,23 @@ class LocationController
$locations_id = $vehicles->groupBy('locations_id')->get(); $locations_id = $vehicles->groupBy('locations_id')->get();
$locations_id = $locations_id->pluck('locations_id')->toArray(); $locations_id = $locations_id->pluck('locations_id')->toArray();
$locations = Location::with('vehicles') $locations = Location::
->with('fboVehicles') // with('vehicles')
->where(['type' => 'production']) // ->with('fboVehicles')
where(['type' => 'production'])
->whereIn('id',$locations_id) ->whereIn('id',$locations_id)
->get() ->get();
->map(function ($location) { // ->map(function ($location) {
$location->vehicle_count = $location->vehicles->count(); // $location->vehicle_count = $location->vehicles->count();
$location->fbo_vehicle_count = $location->fboVehicles->count(); // $location->fbo_vehicle_count = $location->fboVehicles->count();
$location->count = ($location->vehicle_count > 0) ? $location->vehicle_count : $location->fbo_vehicle_count; // $location->count = ($location->vehicle_count > 0) ? $location->vehicle_count : $location->fbo_vehicle_count;
return $location; // return $location;
}); // });
foreach ($locations as &$location) { foreach ($locations as &$location) {
$location->vehicle_count = Vehicle::where(['locations_id'=>$location->id])->count();
$location->fbo_vehicle_count = Vehicle::where(['fbo_locations_id'=>$location->id])->count();
$location->count = ($location->vehicle_count > 0) ? $location->vehicle_count : $location->fbo_vehicle_count;
$location->status = $request->post('status', ''); $location->status = $request->post('status', '');
unset($location->vehicles); unset($location->vehicles);
unset($location->fboVehicles); unset($location->fboVehicles);