Crash on getTableFilterState() on select filter with relationship

Hi! We are looking to prevent initial loading of the first x resources when opening a list resource page and came up with a solution like this:
    protected function getTableQuery(): Builder
    {
        $this->countActiveFilters();
        return parent::getTableQuery()
            ->when(
                $this->filterCount == 0,
                fn ($query) => $query->where(DB::raw('1 = 0')),
            );

        return parent::getTableQuery();
    }


Whereas the countActiveFilters() is as follows. This works fine when using a text input filter or a select filter with manual options. But when using a select filter based on a relationship the page crashes. Is there any way to improve this code? Thanks in advance!

    private function countActiveFilters(): void
    {
        $this->filterCount = 0;
        if (!isset($this->cachedTableFilters)) {
            return;
        }
        foreach ($this->getTableFilters() as $filter) {
            $filterContainer = $this->getTableFilterState($filter->getName()) ?? [];
            $data = array_values($filterContainer);
            $this->filterCount += count(array_filter($data));
        }
    }
Was this page helpful?