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; } }