489 lines
11 KiB
PHP
489 lines
11 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\VehicleFactory;
|
|
use Eloquent;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Schema;
|
|
|
|
/**
|
|
* App\Models\Vehicle
|
|
*
|
|
* @property string $model
|
|
* @property string $displayName
|
|
* @property string $manufacturer
|
|
* @property string $description
|
|
* @property string $type
|
|
* @property string $class
|
|
* @property int $isSold
|
|
* @property float $price
|
|
* @property int $storage
|
|
* @property string $fuelType
|
|
* @property int $seats
|
|
* @property string $hash
|
|
* @property string|null $signedHash
|
|
* @property string|null $hexHash
|
|
* @property float $speed
|
|
* @property float $acceleration
|
|
* @property float $braking
|
|
* @property float $traction
|
|
* @property float $length
|
|
* @property float $width
|
|
* @property float $height
|
|
* @property float $topSpeed
|
|
* @property int $gears
|
|
* @property int $mass
|
|
* @property string $driveTrain
|
|
* @property float $consumption
|
|
* @property int $fuelTankVolume
|
|
* @property int $oilTankVolume
|
|
* @property string $inspiredBy
|
|
* @method static VehicleFactory factory($count = null, $state = [])
|
|
* @method static Builder|Vehicle filter(array $filters)
|
|
* @method static Builder|Vehicle newModelQuery()
|
|
* @method static Builder|Vehicle newQuery()
|
|
* @method static Builder|Vehicle query()
|
|
* @method static Builder|Vehicle whereAcceleration($value)
|
|
* @method static Builder|Vehicle whereBraking($value)
|
|
* @method static Builder|Vehicle whereClass($value)
|
|
* @method static Builder|Vehicle whereConsumption($value)
|
|
* @method static Builder|Vehicle whereDescription($value)
|
|
* @method static Builder|Vehicle whereDisplayName($value)
|
|
* @method static Builder|Vehicle whereDriveTrain($value)
|
|
* @method static Builder|Vehicle whereFuelTankVolume($value)
|
|
* @method static Builder|Vehicle whereFuelType($value)
|
|
* @method static Builder|Vehicle whereGears($value)
|
|
* @method static Builder|Vehicle whereHash($value)
|
|
* @method static Builder|Vehicle whereHeight($value)
|
|
* @method static Builder|Vehicle whereHexHash($value)
|
|
* @method static Builder|Vehicle whereInspiredBy($value)
|
|
* @method static Builder|Vehicle whereIsSold($value)
|
|
* @method static Builder|Vehicle whereLength($value)
|
|
* @method static Builder|Vehicle whereManufacturer($value)
|
|
* @method static Builder|Vehicle whereMass($value)
|
|
* @method static Builder|Vehicle whereModel($value)
|
|
* @method static Builder|Vehicle whereOilTankVolume($value)
|
|
* @method static Builder|Vehicle wherePrice($value)
|
|
* @method static Builder|Vehicle whereSeats($value)
|
|
* @method static Builder|Vehicle whereSignedHash($value)
|
|
* @method static Builder|Vehicle whereSpeed($value)
|
|
* @method static Builder|Vehicle whereStorage($value)
|
|
* @method static Builder|Vehicle whereTopSpeed($value)
|
|
* @method static Builder|Vehicle whereTraction($value)
|
|
* @method static Builder|Vehicle whereType($value)
|
|
* @method static Builder|Vehicle whereWidth($value)
|
|
* @mixin Eloquent
|
|
*/
|
|
class Vehicle extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $primaryKey = 'model';
|
|
protected $table = 'vehicles';
|
|
public $incrementing = false;
|
|
public $timestamps = false;
|
|
protected $guarded = [];
|
|
|
|
public function scopeFilter(
|
|
$query,
|
|
array $filters
|
|
): void {
|
|
$search = $filters['search'] ?? false;
|
|
if ($search) {
|
|
$query->where('displayName', 'like', '%' . $search . '%');
|
|
}
|
|
|
|
unset($filters['search']);
|
|
|
|
$orderByOne = $filters['orderByOne'] ?? null;
|
|
$orderByTwo = $filters['orderByTwo'] ?? null;
|
|
if (!empty($orderByOne) || !empty($orderByTwo)) {
|
|
$orderBy = '';
|
|
if (!empty($orderByOne) && Schema::hasColumn('vehicles', $orderByOne)) {
|
|
$orderBy .= $orderByOne;
|
|
}
|
|
|
|
if (!empty($orderByTwo) && Schema::hasColumn('vehicles', $orderByTwo)) {
|
|
$orderBy .= empty($orderBy) ? $orderByTwo : ', ' . $orderByTwo;
|
|
}
|
|
|
|
$query->orderBy($orderBy);
|
|
}
|
|
|
|
foreach ($filters as $field => $filter) {
|
|
if (empty($filter)) {
|
|
continue;
|
|
}
|
|
|
|
switch ($field) {
|
|
case 'class':
|
|
$query->join('classes', 'vehicles.class', '=', 'classes.name');
|
|
$query->where('classes.name', '=', $filter);
|
|
break;
|
|
case 'manufacturer':
|
|
$query->join('manufacturers', 'vehicles.manufacturer', '=', 'manufacturers.name');
|
|
$query->where('manufacturers.name', '=', $filter);
|
|
break;
|
|
case 'fuelType':
|
|
$query->join('fuel_types', 'vehicles.fuelType', '=', 'fuel_types.name');
|
|
$query->where('fuel_types.name', '=', $filter);
|
|
break;
|
|
default:
|
|
Schema::hasColumn('vehicles', $field);
|
|
$query->where($field, '=', $filter);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getModel(): string
|
|
{
|
|
return $this->model;
|
|
}
|
|
|
|
public function setModel(string $model): Vehicle
|
|
{
|
|
$this->model = $model;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDisplayName(): string
|
|
{
|
|
return $this->displayName;
|
|
}
|
|
|
|
public function setDisplayName(string $displayName): Vehicle
|
|
{
|
|
$this->displayName = $displayName;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getManufacturer(): string
|
|
{
|
|
return $this->manufacturer;
|
|
}
|
|
|
|
public function setManufacturer(string $manufacturer): Vehicle
|
|
{
|
|
$this->manufacturer = $manufacturer;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDescription(): string
|
|
{
|
|
return $this->description;
|
|
}
|
|
|
|
public function setDescription(string $description): Vehicle
|
|
{
|
|
$this->description = $description;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getType(): string
|
|
{
|
|
return $this->type;
|
|
}
|
|
|
|
public function setType(string $type): Vehicle
|
|
{
|
|
$this->type = $type;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getClass(): string
|
|
{
|
|
return $this->class;
|
|
}
|
|
|
|
public function setClass(string $class): Vehicle
|
|
{
|
|
$this->class = $class;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getIsSold(): int
|
|
{
|
|
return $this->isSold;
|
|
}
|
|
|
|
public function setIsSold(int $isSold): Vehicle
|
|
{
|
|
$this->isSold = $isSold;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPrice(): float
|
|
{
|
|
return $this->price;
|
|
}
|
|
|
|
public function setPrice(float $price): Vehicle
|
|
{
|
|
$this->price = $price;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getStorage(): int
|
|
{
|
|
return $this->storage;
|
|
}
|
|
|
|
public function setStorage(int $storage): Vehicle
|
|
{
|
|
$this->storage = $storage;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFuelType(): string
|
|
{
|
|
return $this->fuelType;
|
|
}
|
|
|
|
public function setFuelType(string $fuelType): Vehicle
|
|
{
|
|
$this->fuelType = $fuelType;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getSeats(): int
|
|
{
|
|
return $this->seats;
|
|
}
|
|
|
|
public function setSeats(int $seats): Vehicle
|
|
{
|
|
$this->seats = $seats;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getHash(): string
|
|
{
|
|
return $this->hash;
|
|
}
|
|
|
|
public function setHash(string $hash): Vehicle
|
|
{
|
|
$this->hash = $hash;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getSignedHash(): ?string
|
|
{
|
|
return $this->signedHash;
|
|
}
|
|
|
|
public function setSignedHash(?string $signedHash): Vehicle
|
|
{
|
|
$this->signedHash = $signedHash;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getHexHash(): ?string
|
|
{
|
|
return $this->hexHash;
|
|
}
|
|
|
|
public function setHexHash(?string $hexHash): Vehicle
|
|
{
|
|
$this->hexHash = $hexHash;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getSpeed(): float
|
|
{
|
|
return $this->speed;
|
|
}
|
|
|
|
public function setSpeed(float $speed): Vehicle
|
|
{
|
|
$this->speed = $speed;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getAcceleration(): float
|
|
{
|
|
return $this->acceleration;
|
|
}
|
|
|
|
public function setAcceleration(float $acceleration): Vehicle
|
|
{
|
|
$this->acceleration = $acceleration;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getBraking(): float
|
|
{
|
|
return $this->braking;
|
|
}
|
|
|
|
public function setBraking(float $braking): Vehicle
|
|
{
|
|
$this->braking = $braking;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getTraction(): float
|
|
{
|
|
return $this->traction;
|
|
}
|
|
|
|
public function setTraction(float $traction): Vehicle
|
|
{
|
|
$this->traction = $traction;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getLength(): float
|
|
{
|
|
return $this->length;
|
|
}
|
|
|
|
public function setLength(float $length): Vehicle
|
|
{
|
|
$this->length = $length;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getWidth(): float
|
|
{
|
|
return $this->width;
|
|
}
|
|
|
|
public function setWidth(float $width): Vehicle
|
|
{
|
|
$this->width = $width;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getHeight(): float
|
|
{
|
|
return $this->height;
|
|
}
|
|
|
|
public function setHeight(float $height): Vehicle
|
|
{
|
|
$this->height = $height;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getTopSpeed(): float
|
|
{
|
|
return $this->topSpeed;
|
|
}
|
|
|
|
public function setTopSpeed(float $topSpeed): Vehicle
|
|
{
|
|
$this->topSpeed = $topSpeed;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getGears(): int
|
|
{
|
|
return $this->gears;
|
|
}
|
|
|
|
public function setGears(int $gears): Vehicle
|
|
{
|
|
$this->gears = $gears;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getMass(): int
|
|
{
|
|
return $this->mass;
|
|
}
|
|
|
|
public function setMass(int $mass): Vehicle
|
|
{
|
|
$this->mass = $mass;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDriveTrain(): string
|
|
{
|
|
return $this->driveTrain;
|
|
}
|
|
|
|
public function setDriveTrain(string $driveTrain): Vehicle
|
|
{
|
|
$this->driveTrain = $driveTrain;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getConsumption(): float
|
|
{
|
|
return $this->consumption;
|
|
}
|
|
|
|
public function setConsumption(float $consumption): Vehicle
|
|
{
|
|
$this->consumption = $consumption;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFuelTankVolume(): int
|
|
{
|
|
return $this->fuelTankVolume;
|
|
}
|
|
|
|
public function setFuelTankVolume(int $fuelTankVolume): Vehicle
|
|
{
|
|
$this->fuelTankVolume = $fuelTankVolume;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getOilTankVolume(): int
|
|
{
|
|
return $this->oilTankVolume;
|
|
}
|
|
|
|
public function setOilTankVolume(int $oilTankVolume): Vehicle
|
|
{
|
|
$this->oilTankVolume = $oilTankVolume;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getInspiredBy(): string
|
|
{
|
|
return $this->inspiredBy;
|
|
}
|
|
|
|
public function setInspiredBy(string $inspiredBy): Vehicle
|
|
{
|
|
$this->inspiredBy = $inspiredBy;
|
|
|
|
return $this;
|
|
}
|
|
}
|