Filter down fields if the association has a whitelist.

@param Model $model
@param array $filter
@return array|mixed
770287
public function filterFields(Model $model, $filter = array()) {
        if (empty($filter) || $filter === '*') {
            return $model->fields;
        }

        $fields = array();

        foreach ($filter as $field) {
            list($table, $field) = pluginSplit($field);

            $fields[$field] = $model->fields[$field];
        }

        return $fields;
    }
1104084
protected function callbackFilterList(array $item, $filter)
    {
        foreach ($filter as $field => $term) {

            if (empty($item[$field])) {
                $item[$field] = '0';
            }

            if (!is_string($item[$field])) {
                $item[$field] = (string) (int) !empty($item[$field]);
            }

            if (stripos($item[$field], $term) === false) {
                return false;
            }
        }

        return true;
    }
1058131
public function filter($filter)
    {
        preg_match_all("/(#\w+)/", $filter, $entityNames);
        preg_match_all("/(:\w+)/", $filter, $positions);

        $entityName = is_array($entityNames[0]) && isset($entityNames[0][0]) ? ltrim($entityNames[0][0], '#') : null;
        $position   = is_array($positions[0]) && isset($positions[0][0]) ? $positions[0][0] : null;

        $i = 0;

        $filtered = [];

        foreach ($this->entities as $name => $entity) {
            if ($i === 0 && ($entityName === $name || $entityName === null) && ($position === ':first' || $position === ':highest' || $position === null)) {
                $filtered[] = $entity;
            }

            if ($position === ':any' && ($entityName === $name || $entityName === null)) {
                $filtered[] = $entity;
            }

            if ($i + 1 === $this->entities->count() && ($entityName === $name || $entityName === null) && ($position === ':last' || $position === ':lowest')) {
                $filtered[] = $entity;
            }

            $i++;
        }

        $this->filtered = $filtered;

        return $this;
    }
403458
private static function parseListFilter(array $filter)
    {
        $filter_array = [];

        if ($filter) {
            foreach ($filter as $k => $v) {
                if (!\in_array($k, self::$filterArray, true)) {
                    throw new Exception('Network Filters Not Found');
                }

                if (\is_array($v)) {
                    $filter_array[$k] = $v;
                } else {
                    $filter_array[$k] = [$v];
                }
            }
        } else {
            $filter_array = null;
        }

        return json_encode($filter_array);
    }
345929
public function removeByFilter($filter)
    {
        foreach ($this->where($filter) as $item) {
            $this->remove($item);
        }
        return $this;
    }
722493
public function evaluate(Model $model)
    {
        $filter = false;

        if (!$model[$this->columnName] instanceof RhubarbDateTime) {
            $filter = true;
        } else {
            if (!in_array($model[$this->columnName]->format("N") - 1, $this->validDays)) {
                $filter = true;
            }
        }

        return $filter;
    }
1121646
public function add_filter($field, $filter) {

		if(!is_callable($filter)) return $this;

		if(!isset($this->filters[$field])) $this->filters[$field] = array();
		$this->filters[$field][] = $filter;

		return $this;

	}
922028
protected function handleFilterRequest($filters, $model)
    {
        foreach ($filters as $key=>$value) {
            $model = $model->where($key, '=', $value);
        }
        return $model;
    }
413827
private function getParamsFromFilter(FilterBuilder $filter)
    {
        $result  = [];
        $must    = [];
        $mustNot = [];

        $params = $filter->getParams();

        if ($params['entities']) {
            $result['index'] = $params['entities'];
        }

        if (isset($params['keyword'])) {
            $must[] = new MultiMatchQuery($params['keyword']['value'], $params['keyword']['fields']);
        }

        foreach ($params['params'] ?? [] as $param) {
            list($query, $operator) = $param->createFilter();

            if ($operator == FilterOperators::IN) {
                $must[] = $query;
            } else {
                $mustNot[] = $query;
            }

        }

        if ($mustNot || $must) {

            $query = new QueryBuilder();
            if ($mustNot) {
                $query->setMustNot(new MustNotQuery($mustNot));
            }
            if ($must) {
                $query->setMust(new MustQuery($must));
            }

            $result['query'] = $query->toArray();
        }

        return $result;
    }
1298092
private function fetchModelsFromClipboard(FilterInterface $filter = null, ModelIdInterface $parentModelId = null)
    {
        $environment    = $this->getEnvironment();
        $dataDefinition = $environment->getDataDefinition();

        if (!$filter) {
            $filter = new Filter();
        }

        $basicDefinition   = $dataDefinition->getBasicDefinition();
        $modelProviderName = $basicDefinition->getDataProvider();
        $filter->andModelIsFromProvider($modelProviderName);
        if ($parentModelId) {
            $filter->andParentIsFromProvider($parentModelId->getDataProviderName());
        } else {
            $filter->andHasNoParent();
        }

        $environment = $this->getEnvironment();
        $clipboard   = $environment->getClipboard();
        $items       = $clipboard->fetch($filter);
        $actions     = [];

        foreach ($items as $item) {
            $model = null;

            if (!$item->isCreate() && $item->getModelId()) {
                $model = $this->modelCollector->getModel($item->getModelId()->getId(), $item->getDataProviderName());
            }

            $actions[] = [
                'model' => $model,
                'item'  => $item,
            ];
        }

        return $actions;
    }
1224430
public function deleteMany(array $filter, array $options = [])
    {
        list($bulkOptions, $options) = self::extractBulkWriteOptions($options);
        $model = new DeleteMany($filter, $options);
        $bulkWriteResult = $this->bulkWrite([$model], $bulkOptions);

        return new DeleteResult($bulkWriteResult);
    }
671752
public function scopeFilter($query, array $input = [], $filter = null)
    {
        // Resolve the current Model's filter
        if ($filter === null) {
            $filter = $this->getModelFilterClass();
        }

        // Create the model filter instance
        $modelFilter = new $filter($query, $input);

        // Set the input that was used in the filter (this will exclude empty strings)
        $this->filtered = $modelFilter->input();

        // Return the filter query
        return $modelFilter->handle();
    }
190081
public function getCollection(HasMedia $model, string $collectionName, $filter = []): Collection
    {
        return $this->applyFilterToMediaCollection($model->loadMedia($collectionName), $filter);
    }
49453
public function withFilter(Filter $filter)
    {
        if ($this->value->isNull()) {
            return null;
        }

        return $this->applyFilter($filter);
    }
710467
protected function filterCanBeApplied($filter, $value)
    {
        $filterExists = method_exists($this, $filter);
        $hasValue = $value !== '' && $value !== null;
        $valueIsLegit = $hasValue || in_array($filter, $this->implicitFilters);

        return $filterExists && $valueIsLegit;
    }
741266
public function getFilteredOptions(string $filter) : array
    {
        $options = call_user_func($this->fieldOptionsLoader, $filter);
        return (new ArrayFieldOptions($options))->getAll();
    }
291494
public function search(string $model, array $fields) : ?array
  {
    $response = array();
    foreach($fields as $param => $value) {
      $check = $model::where($param, $value)->first();

      if ($check != null) {
        $response = array_merge($response, array($param => "The $param has already been taken."));
      }
    }

    return $response;
  }