Adds model, repo, controller, and request classes for Vehicle and Convoy. Registers routes for vehicles and convoys, updates client store. Adds front‑end files to list, add, edit vehicles. Cleans up console logging from client store.
43 lines
1.3 KiB
PHP
43 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Repositories;
|
|
|
|
use App\Models\Vehicle;
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
|
|
class VehicleRepository extends BaseRepository implements VehicleRepositoryInterface
|
|
{
|
|
public function __construct(Vehicle $model)
|
|
{
|
|
parent::__construct($model);
|
|
}
|
|
|
|
public function paginate(int $perPage = 15, array $filters = []): LengthAwarePaginator
|
|
{
|
|
$query = $this->model->newQuery()->with(['primaryUser', 'convoys']);
|
|
|
|
if (! empty($filters['search'])) {
|
|
$query->where(function ($q) use ($filters) {
|
|
$q->where('brand', 'like', '%' . $filters['search'] . '%')
|
|
->orWhere('model', 'like', '%' . $filters['search'] . '%')
|
|
->orWhere('registration_number', 'like', '%' . $filters['search'] . '%');
|
|
});
|
|
}
|
|
|
|
if (! empty($filters['status'])) {
|
|
$query->where('status', $filters['status']);
|
|
}
|
|
|
|
if (! empty($filters['vehicle_type'])) {
|
|
$query->where('vehicle_type', $filters['vehicle_type']);
|
|
}
|
|
|
|
$sortField = $filters['sort_by'] ?? 'created_at';
|
|
$sortDirection = $filters['sort_direction'] ?? 'desc';
|
|
|
|
return $query->orderBy($sortField, $sortDirection)->paginate($perPage);
|
|
}
|
|
}
|