eaa05d68c1
- Filament v5 multiFactorAuthentication enabled on both panels (App + Email) - HasAppAuthentication + HasEmailAuthentication on User and SuperAdmin - Migration: app_authentication_secret + recovery_codes + email_authentication_at - Sanctum REST API: /api/v1/login, /me, clients, vehicles, work-orders - EnsureTokenMatchesTenant middleware blocks cross-tenant token usage - CsvImportExport service: clients + vehicles bulk via plain CSV - Import/Export buttons on Client + Vehicle list pages - ApiTokens page in tenant panel (generate/revoke + last-used) - BackupAllTenantsCommand + scheduler (daily 03:00, retain 14 days) - Background scheduler in entrypoint.sh
67 lines
2.2 KiB
PHP
67 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Models\Tenant\Vehicle;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class VehicleApiController
|
|
{
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
$q = Vehicle::query()->with('client:id,name,phone');
|
|
if ($s = $request->query('search')) {
|
|
$q->where(function ($qq) use ($s) {
|
|
$qq->where('plate', 'like', "%{$s}%")
|
|
->orWhere('vin', 'like', "%{$s}%")
|
|
->orWhere('brand', 'like', "%{$s}%")
|
|
->orWhere('model', 'like', "%{$s}%");
|
|
});
|
|
}
|
|
return response()->json($q->orderBy('plate')->paginate(min((int) $request->query('per_page', 25), 100)));
|
|
}
|
|
|
|
public function show(Vehicle $vehicle): JsonResponse
|
|
{
|
|
return response()->json($vehicle->load(['client', 'workOrders' => fn ($q) => $q->latest()->limit(10)]));
|
|
}
|
|
|
|
public function store(Request $request): JsonResponse
|
|
{
|
|
$data = $request->validate([
|
|
'client_id' => 'required|exists:clients,id',
|
|
'plate' => 'required|string|max:30',
|
|
'vin' => 'nullable|string|max:30',
|
|
'brand' => 'nullable|string|max:60',
|
|
'model' => 'nullable|string|max:60',
|
|
'year' => 'nullable|integer|min:1900|max:2100',
|
|
'mileage' => 'nullable|integer|min:0',
|
|
'fuel' => 'nullable|string|max:30',
|
|
'engine' => 'nullable|string|max:60',
|
|
'gearbox' => 'nullable|string|max:30',
|
|
'color' => 'nullable|string|max:30',
|
|
'notes' => 'nullable|string',
|
|
]);
|
|
$v = Vehicle::create($data);
|
|
return response()->json($v, 201);
|
|
}
|
|
|
|
public function update(Request $request, Vehicle $vehicle): JsonResponse
|
|
{
|
|
$data = $request->validate([
|
|
'plate' => 'sometimes|string|max:30',
|
|
'mileage' => 'nullable|integer|min:0',
|
|
'notes' => 'nullable|string',
|
|
]);
|
|
$vehicle->update($data);
|
|
return response()->json($vehicle);
|
|
}
|
|
|
|
public function destroy(Vehicle $vehicle): JsonResponse
|
|
{
|
|
$vehicle->delete();
|
|
return response()->json(['ok' => true]);
|
|
}
|
|
}
|