fbo港口
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller;
|
||||
|
||||
use app\model\Vehicle;
|
||||
use app\util\Util;
|
||||
use support\Request;
|
||||
|
||||
class VehicleController
|
||||
{
|
||||
/**
|
||||
* Mask VIN number by showing only first 2 and last 6 characters
|
||||
*/
|
||||
private function maskVin($vin)
|
||||
{
|
||||
if (strlen($vin) <= 8) {
|
||||
return $vin;
|
||||
}
|
||||
return substr($vin, 0, 2) . str_repeat('*', strlen($vin) - 8) . substr($vin, -6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all vehicles with their locations
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$vehicles = Vehicle::with('location')->with('finalLocation')->get();
|
||||
$vehicles->each(function ($vehicle) {
|
||||
if (isset($vehicle->vin)) {
|
||||
$vehicle->vin = $this->maskVin($vehicle->vin);
|
||||
}
|
||||
});
|
||||
$result = ['list' => $vehicles,'count'=>count($vehicles)];
|
||||
return Util::success($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific vehicle with its location
|
||||
*/
|
||||
public function show(Request $request, $id)
|
||||
{
|
||||
$vehicle = Vehicle::with('location')->find($id);
|
||||
if (!$vehicle) {
|
||||
return Util::fail($vehicle,'Vehicle not found');
|
||||
}
|
||||
if (isset($vehicle->vin)) {
|
||||
$vehicle->vin = $this->maskVin($vehicle->vin);
|
||||
}
|
||||
return Util::success($vehicle);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user