325 lines
6.4 KiB
PHP
325 lines
6.4 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 Illuminate\Support\Carbon;
|
|
use Schema;
|
|
|
|
/**
|
|
* App\Models\Vehicle
|
|
*
|
|
* @property int $id
|
|
* @property Carbon|null $created_at
|
|
* @property Carbon|null $updated_at
|
|
* @property string $name
|
|
* @property string $image_path
|
|
* @property int $storage
|
|
* @property int $fuel_volume
|
|
* @property int $seats
|
|
* @property float $price
|
|
* @property float $top_speed
|
|
* @property int $vehicle_class_id
|
|
* @property int $fuel_type_id
|
|
* @property int $brand_id
|
|
* @property int $vendor_id
|
|
* @method static VehicleFactory factory($count = null, $state = [])
|
|
* @method static Builder|Vehicle newModelQuery()
|
|
* @method static Builder|Vehicle newQuery()
|
|
* @method static Builder|Vehicle query()
|
|
* @method static Builder|Vehicle whereBrandId($value)
|
|
* @method static Builder|Vehicle whereCreatedAt($value)
|
|
* @method static Builder|Vehicle whereFuelTypeId($value)
|
|
* @method static Builder|Vehicle whereFuelVolume($value)
|
|
* @method static Builder|Vehicle whereId($value)
|
|
* @method static Builder|Vehicle whereName($value)
|
|
* @method static Builder|Vehicle wherePrice($value)
|
|
* @method static Builder|Vehicle whereSeats($value)
|
|
* @method static Builder|Vehicle whereStorage($value)
|
|
* @method static Builder|Vehicle whereTopSpeed($value)
|
|
* @method static Builder|Vehicle whereUpdatedAt($value)
|
|
* @method static Builder|Vehicle whereVehicleClassId($value)
|
|
* @method static Builder|Vehicle whereVendorId($value)
|
|
* @mixin Eloquent
|
|
*/
|
|
class Vehicle extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getId(): int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
/**
|
|
* @param int $id
|
|
*
|
|
* @return Vehicle
|
|
*/
|
|
public function setId(int $id): Vehicle
|
|
{
|
|
$this->id = $id;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getName(): string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
/**
|
|
* @param string $name
|
|
*
|
|
* @return Vehicle
|
|
*/
|
|
public function setName(string $name): Vehicle
|
|
{
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getStorage(): int
|
|
{
|
|
return $this->storage;
|
|
}
|
|
|
|
/**
|
|
* @param int $storage
|
|
*
|
|
* @return Vehicle
|
|
*/
|
|
public function setStorage(int $storage): Vehicle
|
|
{
|
|
$this->storage = $storage;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getFuelVolume(): int
|
|
{
|
|
return $this->fuel_volume;
|
|
}
|
|
|
|
/**
|
|
* @param int $fuel_volume
|
|
*
|
|
* @return Vehicle
|
|
*/
|
|
public function setFuelVolume(int $fuel_volume): Vehicle
|
|
{
|
|
$this->fuel_volume = $fuel_volume;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getSeats(): int
|
|
{
|
|
return $this->seats;
|
|
}
|
|
|
|
/**
|
|
* @param int $seats
|
|
*
|
|
* @return Vehicle
|
|
*/
|
|
public function setSeats(int $seats): Vehicle
|
|
{
|
|
$this->seats = $seats;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return float
|
|
*/
|
|
public function getPrice(): float
|
|
{
|
|
return $this->price;
|
|
}
|
|
|
|
/**
|
|
* @param float $price
|
|
*
|
|
* @return Vehicle
|
|
*/
|
|
public function setPrice(float $price): Vehicle
|
|
{
|
|
$this->price = $price;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return float
|
|
*/
|
|
public function getTopSpeed(): float
|
|
{
|
|
return $this->top_speed;
|
|
}
|
|
|
|
/**
|
|
* @param float $top_speed
|
|
*
|
|
* @return Vehicle
|
|
*/
|
|
public function setTopSpeed(float $top_speed): Vehicle
|
|
{
|
|
$this->top_speed = $top_speed;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getVehicleClassId(): int
|
|
{
|
|
return $this->vehicle_class_id;
|
|
}
|
|
|
|
/**
|
|
* @param int $vehicle_class_id
|
|
*
|
|
* @return Vehicle
|
|
*/
|
|
public function setVehicleClassId(int $vehicle_class_id): Vehicle
|
|
{
|
|
$this->vehicle_class_id = $vehicle_class_id;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getFuelTypeId(): int
|
|
{
|
|
return $this->fuel_type_id;
|
|
}
|
|
|
|
/**
|
|
* @param int $fuel_type_id
|
|
*
|
|
* @return Vehicle
|
|
*/
|
|
public function setFuelTypeId(int $fuel_type_id): Vehicle
|
|
{
|
|
$this->fuel_type_id = $fuel_type_id;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getBrandId(): int
|
|
{
|
|
return $this->brand_id;
|
|
}
|
|
|
|
/**
|
|
* @param int $brand_id
|
|
*
|
|
* @return Vehicle
|
|
*/
|
|
public function setBrandId(int $brand_id): Vehicle
|
|
{
|
|
$this->brand_id = $brand_id;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getVendorId(): int
|
|
{
|
|
return $this->vendor_id;
|
|
}
|
|
|
|
/**
|
|
* @param int $vendor_id
|
|
*
|
|
* @return Vehicle
|
|
*/
|
|
public function setVendorId(int $vendor_id): Vehicle
|
|
{
|
|
$this->vendor_id = $vendor_id;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getImagePath(): string
|
|
{
|
|
return $this->image_path;
|
|
}
|
|
|
|
/**
|
|
* @param string $image_path
|
|
*
|
|
* @return Vehicle
|
|
*/
|
|
public function setImagePath(string $image_path): Vehicle
|
|
{
|
|
$this->image_path = $image_path;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function scopeFilter(
|
|
$query,
|
|
array $filters
|
|
): void {
|
|
$search = $filters['search'] ?? false;
|
|
if ($search) {
|
|
$query->where('name', 'like', '%' . $search . '%');
|
|
}
|
|
|
|
unset($filters['search']);
|
|
|
|
$orderByOne = $filters['orderByOne'] ?? false;
|
|
$orderByTwo = $filters['orderByTwo'] ?? false;
|
|
if ($orderByOne || $orderByTwo) {
|
|
$orderBy = '';
|
|
if ($orderByOne && Schema::hasColumn('vehicles', $orderByOne)) {
|
|
$orderBy .= $orderByOne;
|
|
}
|
|
|
|
if ($orderByTwo && Schema::hasColumn('vehicles', $orderByTwo)) {
|
|
$orderBy .= empty($orderBy) ? $orderByTwo : ', ' . $orderByTwo;
|
|
}
|
|
|
|
$query->orderBy($orderBy);
|
|
}
|
|
|
|
foreach ($filters as $field => $filter) {
|
|
Schema::hasColumn('vehicles', $field);
|
|
$query->where($field, '=', $filter);
|
|
}
|
|
}
|
|
}
|