/** * Apply the inquiry with an optional operator query to the query itself. * * @param \Illuminate\Database\Eloquent\Builder $query * @param string $attribute * @param \Bycedric\Inquiry\Queries\Query $operator * @param bool $comparator * @return \Illuminate\Database\Eloquent\Builder */ private function applyQuery($query, $attribute, $operator, $comparator = 'and') { // check if operator is a range query if ($operator instanceof RangeQuery) { // iterate the values and apply to the query for each seperate operator foreach ($operator->getValues() as $value) { $this->applyQuery($query, $attribute, $value, $operator->isAllSameOperator('=') ? 'or' : 'and'); } // stop executing return $query; } // get the value and method $value = $operator->getValue(); $method = $operator->getMethod(); // check if the value is null if (is_null($value)) { // check if the method or operator is an inverter if ($operator->isNot()) { // applying whereNotNull return $query->whereNotNull($attribute, $comparator); } // applying whereNull return $query->whereNull($attribute, $comparator); } // check if the method is LIKE if ($method == 'LIKE') { // add % to the value $value = '%' . str_replace(' ', '%', $value) . '%'; } // applying query return $query->where($attribute, $method, $value, $comparator); }