1
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user