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