42 lines
1.0 KiB
PHP
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);
|
|
}
|
|
}
|