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 = $locations_id->pluck('locations_id')->toArray();
$locations = Location::with('vehicles')
->with('fboVehicles')
->where(['type' => 'production'])
$locations = Location::
// with('vehicles')
// ->with('fboVehicles')
where(['type' => 'production'])
->whereIn('id',$locations_id)
->get()
->map(function ($location) {
$location->vehicle_count = $location->vehicles->count();
$location->fbo_vehicle_count = $location->fboVehicles->count();
$location->count = ($location->vehicle_count > 0) ? $location->vehicle_count : $location->fbo_vehicle_count;
return $location;
});
->get();
// ->map(function ($location) {
// $location->vehicle_count = $location->vehicles->count();
// $location->fbo_vehicle_count = $location->fboVehicles->count();
// $location->count = ($location->vehicle_count > 0) ? $location->vehicle_count : $location->fbo_vehicle_count;
// return $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', '');
unset($location->vehicles);
unset($location->fboVehicles);