Custom Filter and Query Scope

Hi everyone, I'm facing some difficulties understanding how Filament behaves behind the scenes regarding custom filters and queries. To elaborate further: I have a resource displaying a table linked to a Laravel model. However, the table is extremely large (with several million records), and I've applied a basic scope to filter the query.

MyScope:
I take the latest record, read the value of a column (lunivid_serie) , and filter the entire query for the found value:
public function apply(Builder $builder, Model $model): void
    {

        $latestSeries = DB::table('kiid_mail_report_d')
                    ->select('*')
                    ->orderByDesc('tuts')
                    ->first();


        $builder->where('lunivid_serie', '=', $latestSeries->lunivid_serie);
    }


The issue arises when, through a custom filter, I try to provide the ability to modify this filter. I'm attempting to access the $query variable using the withoutGlobalScopes() method, but the query fails without an apparent reason (the records exist and are present; when I do dd($query), everything seems to be correctly set up).

This filter is NOT working...
code in the comment...


Can anyone explain to me how to have a general filter ONLY on the table and a dynamically custom filter based on the filter, so that the querydoesn't start with the same filter set to initially display the data in the table? It seems like an extremely straightforward operation, and it's surprising that there isn't a clear and precise way to achieve this result. Thanks to everyone.
Was this page helpful?