request = $request; $this->params = $request->all(); } public function apply($builder) { $this->queryBuilder = $builder; $filters = array_filter($this->request->only($this->filters)); foreach ($filters as $filter => $value) { if (method_exists($this, $filter)) { $this->$filter($value, $this->queryBuilder); } } $this->afterApply(); return $this->queryBuilder; } public function getDeliveryAppointmentCarQuery(): Builder { if (!$this->deliveryAppointmentCarQuery){ $this->deliveryAppointmentCarQuery = DeliveryAppointmentCar::query()->select('id'); } return $this->deliveryAppointmentCarQuery; } public function afterApply(){ if ($this->deliveryAppointmentCarQuery){ $this->queryBuilder->whereIn('delivery_appointment_car_id',$this->deliveryAppointmentCarQuery); } } public function id($ids){ $this->searchWay($this->queryBuilder,$ids,'id'); } public function owner_id($owner_id){ $this->searchWay($this->queryBuilder,$owner_id,'owner_id'); } public function warehouse_id($warehouse_id){ $this->searchWay($this->queryBuilder,$warehouse_id,'warehouse_id'); } public function appointment_number($appointment_number){ $this->searchWay($this->getDeliveryAppointmentCarQuery(),$appointment_number,'appointment_number'); } public function number($number){ $this->searchWay($this->queryBuilder,$number,'number'); } public function created_at_start($created_at_start){ $this->queryBuilder->where('created_at','>=',$created_at_start." 00:00:00"); } public function created_at_end($created_at_end){ $this->queryBuilder->where('created_at','<=',$created_at_end." 23:59:59"); } }