Finds the last model matching the given filters.

@param \Rhubarb\Stem\Filters\Filter[] $filters
@throws RecordNotFoundException
@return Model|static
420976
public static function findLast(Filter ...$filters)
    {
        $results = static::find(...$filters);
        $modelClass = get_called_class();
        /** @var Model $model */
        $model = new $modelClass();
        $results->addSort($model->getUniqueIdentifierColumnName(), false);

        if (sizeof($results) == 0) {
            throw new RecordNotFoundException(get_called_class(), 0);
        }

        return $results[0];
    }
412410
public static function firstOrFail($filters, $fields = null)
    {
        if (!$r = static::first($filters, $fields)) {
            $exception = new NotFoundException([
                'No record for `:model` model with `:query` query',
                'model' => static::class,
                'query' => json_encode($filters, JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE)
            ]);
            $exception->model = static::class;
            $exception->filters = $filters;

            throw $exception;
        }

        return $r;
    }
284714
public function setFilters($filters) {
		if ($filters instanceof Collection) {
			$filters = $filters->toArray();
		}
		
		$this->filters = $filters;

		return $this;
	}
386239
public function filter(array $filters)
	{
		foreach ($filters as $filter) {
			if ($filter->isValueSet()) {
				if ($filter->hasConditionCallback()) {
					$data = (array) call_user_func_array(
						$filter->getConditionCallback(),
						[$this->data, $filter->getValue()]
					);
					$this->setData($data);
				} else {
					$data = array_filter($this->data, function ($row) use ($filter) {
						return $this->applyFilter($row, $filter);
					});
					$this->setData($data);
				}
			}
		}

		return $this;
	}
715799
public function setFilters($filters)
    {
        if ($filters === null)
            $filters = [];
        else if (!is_array($filters))
            throw new \Exception('Filters should be null or array');

        foreach ($filters as $column => $filter) {
            $found = [];
            foreach ($this->getColumns() as $id => $params) {
                if ($id == $column) {
                    foreach ($filter as $name => $value) {
                        if (in_array($name, $params['filters']))
                            $found[$name] = $value;
                    }
                    break;
                }
            }

            if (count($found) > 0)
                $filters[$column] = $found;
            else
                unset($filters[$column]);
        }

        $this->filters = $filters;
        return $this;
    }
729107
public function setFilters(array $filters): AbstractRepository
    {
        foreach ($filters as $f => $v) {
            $this->filterBy($f, $v);
        }

        return $this;
    }
1250090
public function filterAll(array $filters)
    {
        $filterList = [];
        foreach ($filters as $key => $value) {
            $filterList[] = $key . ':' . $value;
        }

        $result = $this->connection()->get($this->getEndpoint(), ['filter' => implode(',', $filterList)], true);

        return $this->collectionFromResult($result);
    }
1228752
public function filters(Collection $filters)
    {
        foreach ($filters as $element) {
            // do not apply filter if no request var were found.
            if (!app('request')->has($element->id())) {
                continue;
            }

            $this->assemblyQuery($element);
        }

        return $this;
    }
1033980
protected function filterQuery(&$query, $filters) {
        $table = $this->model->getTable();
        foreach ($filters as $property => $value) {
            $type = DB::connection()->getDoctrineColumn($table, $property)->getType()->getName();

            $property = $table . '.' . $property;

            if (str_contains($type, 'time')) {
                $start = date('Y-m-d H:i:s', strtotime($value->start));
                $end = date('Y-m-d H:i:s', strtotime($value->end));
                $query->whereBetween($property, array($start, $end));
            } else if ($type === 'integer') {
                $query->where($property, $value);
            } else {
                $query->where($property, 'ilike', '%' . $value . '%');
            }
        }

        return $query;
    }
537329
public function filter($filters = null)
    {
        if ($filters) {
            $this->query->where(function($query) use ($filters) {
                foreach ($filters as $where) {
                    // Use 'and' as default boolean method
                    if (!isset($where[3])) { $where[3] = 'and'; }

                    // Sugar for 'IN' operations
                    if ($where[1] == '=' && gettype($where[2]) == 'array') {
                        $where[1] = 'in';

                    } else if ($where[1] == '!=' && $where[2] == null) {
                        // Workaround to support whereNotNull
                        $where[1] = 'not_null';
                        $where[2] = 'and';
                    }

                    if (preg_match('/^[a-z_]+$/', $where[1]) !== 0 && strtolower($where[1]) !== 'like') {
                        $method = 'where' . ucfirst(\Illuminate\Support\Str::camel($where[1]));
                        $query->{$method}($where[0], $where[2], $where[3]);
                    } else {
                        $query->where($where[0], $where[1], $where[2], $where[3]);
                    }
                }
            });
        }

        return $this;
    }
527886
public function applyFilters($filters)
    {
        foreach ($filters as $key => $value) {
            $this->filters[$key] = $value;
        }

        return $this;
    }
1039024
public function addFilters(array $filters)
    {
        foreach ($filters as $filter) {
            if ($filter === null) {
                continue;
            }

            $this->addFilter($filter);
        }

        return $this;
    }
298618
public function getAll(array $filters = null)
    {
        $search = $this->repository->createSearch();
        $search->addQuery(new MatchAllQuery());
        $search->setScroll('2m');

        if ($filters) {
            foreach ($filters as $field => $value) {
                $search->addQuery(new TermsQuery($field, $value));
            }
        }

        return $this->repository->findDocuments($search);
    }
1194976
public function filter(...$filters)
    {
        if (sizeof($filters) == 0) {
            return $this;
        }

        $andGroup = new AndGroup();

        if (is_array($filters[0])) {
            $filters = $filters[0];
        }

        foreach ($filters as $filter) {
            if (!($filter instanceof Filter)) {
                throw new FilterNotSupportedException('One or more of the parameters, or one or more elements of an array parameter, was not of the Filter Class');
            }

            $andGroup->addFilters($filter);
        }

        if (sizeof($filters) == 1) {
            $andGroup = $filters[0];
        }

        if (is_null($this->filter)) {
            $this->filter = $andGroup;
        } else {
            $this->filter = new AndGroup([$andGroup, $this->filter]);
        }

        $this->invalidate();

        return $this;
    }
1237803
protected function getDefaultFilterFunction(array $filters): Closure
    {
        return function (Media $media) use ($filters) {
            foreach ($filters as $property => $value) {
                if (! Arr::has($media->custom_properties, $property)) {
                    return false;
                }

                if (Arr::get($media->custom_properties, $property) !== $value) {
                    return false;
                }
            }

            return true;
        };
    }
1052485
public function filter(array $filters)
	{
		foreach ($filters as $filter) {
			if ($filter->isValueSet()) {
				if ($filter->hasConditionCallback()) {
					Callback::invokeArgs(
						$filter->getConditionCallback(),
						[$this->data_source, $filter->getValue()]
					);
				} else {
					if ($filter instanceof Filter\FilterText) {
						$this->applyFilterText($filter);
					} elseif ($filter instanceof Filter\FilterMultiSelect) {
						$this->applyFilterMultiSelect($filter);
					} elseif ($filter instanceof Filter\FilterSelect) {
						$this->applyFilterSelect($filter);
					} elseif ($filter instanceof Filter\FilterDate) {
						$this->applyFilterDate($filter);
					} elseif ($filter instanceof Filter\FilterDateRange) {
						$this->applyFilterDateRange($filter);
					} elseif ($filter instanceof Filter\FilterRange) {
						$this->applyFilterRange($filter);
					}
				}
			}
		}

		return $this;
	}
1285672
public function addFilter($filters)
    {
        $filters = (array) AnConfig::unbox($filters);

        foreach ($filters as $filter) {
            if (!($filter instanceof LibBaseTemplateFilterInterface)) {
                $filter = $this->getFilter($filter);
            }
            
            //Enqueue the filter in the command chain
            $this->getCommandChain()->enqueue($filter);
            
            //Store the filter
            $this->_filters[$filter->getIdentifier()->name] = $filter;
        }
        
        return $this;
    }