fleetCatalogue/resources/views/vehicles/index.blade.php

87 lines
4.8 KiB
PHP

@php
use App\Models\Vehicle;
/** @var Vehicle $vehicle */
@endphp
<x-layout title="{{ __('Vehicles') }}">
<x-slot:breadcrumb>
{{ Breadcrumbs::render('vehicles') }}
</x-slot:breadcrumb>
<x-slot name="header">
<h2>{{ __('Vehicles') }}</h2>
<x-searchbar-select2 post="{{ route('vehicles') }}" inputClasses="w-[20rem]"
autocomplete="{{ route('vehicles.autocomplete') }}"
placeholder="Select Vehicle" templateResult="true"
templateSelection="true" text="item.vehicle_name">
<x-select-dropdown-hover alpineVariable="vehicle_class_id" placeholder="Pick a Vehicle Class..."
:enums="$vehicleClasses" functionCall="getVehicleClassName"/>
<x-select-dropdown-hover alpineVariable="brand_id" placeholder="Pick a Brand..."
:enums="$brands" functionCall="getBrandName"/>
<x-select-dropdown-hover alpineVariable="fuel_type_id" placeholder="Pick a Fuel Type..."
:enums="$fuelTypes" functionCall="getFuelTypeName"/>
<x-select-dropdown-hover alpineVariable="vendor_id" placeholder="Pick a Vendor..."
:enums="$vendors" functionCall="getVendorName"/>
<x-select-dropdown-hover alpineVariable="listMode" :enums="['gridCards', 'tableHorizontal', 'tableVertical']" placeholder="Pick a display mode for the list..." default="gridCards"/>
</x-searchbar-select2>
</x-slot>
@php
$fields = explode(',', env('FIELDS', ''));
$headerValues = [
'image' => ['type' => 'string', 'value' => __('Photo'),],
'id' => ['type' => 'string', 'value' => __('Id')],
'name' => ['type' => 'string', 'value' => __('Name')],
'brand' => ['type' => 'string', 'value' => __('Brand')],
'class' => ['type' => 'string', 'value' => __('Class')],
'storage' => ['type' => 'string', 'value' => __('Storage')],
'fuel_type' => ['type' => 'string', 'value' => __('Fuel Type')],
'fuel_volume' => ['type' => 'string', 'value' => __('Fuel Volume')],
'seats' => ['type' => 'string', 'value' => __('Seats')],
'top_speed' => ['type' => 'string', 'value' => __('Top Speed')],
'price' => ['type' => 'string', 'value' => __('Price')],
'vendor' => ['type' => 'string', 'value' => __('Vendor')],
];
$values = [];
foreach ($fields as $field) {
$values[0][$field] = $headerValues[$field];
}
$index = 0;
foreach ($vehicles as $key => $vehicle) {
$index++;
$fieldValues = [
'image' => ['type' => 'image', 'value' => asset('img/vehicles/' . $vehicle->getVehicleId() . '.png')],
'id' => ['type' => 'int', 'value' => $vehicle->getVehicleId()],
'name' => ['type' => 'string', 'value' => $vehicle->getVehicleName()],
'brand' => ['type' => 'string', 'value' => $brands->firstWhere('brand_id', '=', $vehicle->getBrandId())->getBrandName()],
'class' => ['type' => 'string', 'value' => $vehicleClasses->firstWhere('vehicle_class_id', '=', $vehicle->getVehicleClassId())->getVehicleClassName()],
'storage' => ['type' => 'int', 'value' => $vehicle->getVehicleStorage()],
'fuel_type' => ['type' => 'string', 'value' => $fuelTypes->firstWhere('fuel_type_id', '=', $vehicle->getFuelTypeId())->getFuelTypeName()],
'fuel_volume' => ['type' => 'int', 'value' => $vehicle->getVehicleFuelVolume(), 'unit' => env('FUEL_VOLUME_UNIT', 'l')],
'seats' => ['type' => 'int', 'value' => $vehicle->getVehicleSeats()],
'top_speed' => ['type' => 'int', 'value' => $vehicle->getVehicleTopSpeed(), 'unit' => env('SPEED_UNIT', 'km/h')],
'price' => ['type' => 'int', 'value' => $vehicle->getVehiclePrice(), 'unit' => env('CURRENCY', '$')],
'vendor' => ['type' => 'string', 'value' => $vendors->firstWhere('vendor_id', '=', $vehicle->getVendorId())->getVendorName()],
];
foreach ($fields as $field) {
$values[$index][$field] = $fieldValues[$field];
}
}
@endphp
@switch(app('request')->input('listMode') ?? env('DEFAULT_DISPLAY_MODE'))
@case('tableHorizontal')
@case('tableVertical')
<x-table.table :mode="app('request')->input('listMode') ?? env('DEFAULT_DISPLAY_MODE')" :values="$values" />
@break
@default
<x-grid>
@foreach($vehicles as $key => $vehicle)
<x-vehicles.card :vehicle="$vehicle"
:brand="$brands->firstWhere('brand_id', '=', $vehicle->getBrandId())->getBrandName()"
:class="$vehicleClasses->firstWhere('vehicle_class_id', '=', $vehicle->getVehicleClassId())->getVehicleClassName()"
:vendor="$vendors->firstWhere('vendor_id', '=', $vehicle->getVendorId())->getVendorName()"
:fuel-type="$fuelTypes->firstWhere('fuel_type_id', '=', $vehicle->getFuelTypeId())->getFuelTypeName()"/>
@endforeach
</x-grid>
@endswitch
{{ $vehicles->links() }}
</x-layout>