private static function applySearchFilter(&$query, $filter)
    {
        $filter_type = Arr::get($filter, 'settings.filter');
        $method = Arr::get($filter, 'method');
        $arguments = Arr::get($filter, 'arguments');
        $attributes = Arr::get($filter, 'settings.attributes');
        $positive = Arr::get($filter, 'positive');

        if ($filter_type !== 'scope' && is_array($arguments)) {
            array_unshift($arguments, '');
        }

        $query->where(function ($query) use ($filter_type, $attributes, $method, $arguments, $positive) {
            $count = 0;
            foreach ($attributes as $attribute_name) {
                // Place attribute name into argument.
                if ($filter_type !== 'scope' && is_array($arguments)) {
                    $arguments[0] = $attribute_name;

                // Argument is raw and using sprintf.
                } elseif (!is_array($arguments)) {
                    $arguments = [sprintf($arguments, self::quoteIdentifier($attribute_name))];
                }

                if ($filter_type === 'scope') {
                    $arguments[] = $positive;
                }

                $query->$method(...$arguments);

                // Apply an or to the where.
                if ($filter_type !== 'scope' && $count === 0 && $positive) {
                    $method = 'or'.Str::studly($method);
                }

                $count++;
            }
        });
    }