Files
car_info/app/controller/LocationController.php
T
2025-04-30 11:30:08 +08:00

42 lines
1.0 KiB
PHP

<?php
namespace app\controller;
use app\model\Location;
use util\Util;
use support\Request;
class LocationController
{
/**
* Get all locations that have vehicles
*/
public function index(Request $request)
{
$locations = Location::with('vehicles')
->with('fboVehicles')
->get()
->map(function ($location) {
$location->vehicle_count = $location->vehicles->count();
$location->fbo_vehicle_count = $location->fboVehicles->count();
return $location;
});
return Util::success($locations);
}
/**
* Get a specific location with its vehicles
*/
public function show(Request $request, $id)
{
$location = Location::hasVehicles()
->with('vehicles')
->find($id);
if (!$location) {
return Util::fail(null, 'Location not found or has no vehicles');
}
return Util::success($location);
}
}