#Filament filters my leftJoin

6 messages · Page 1 of 1 (latest)

wet plank
#

I am applying a leftjoin to my filter base query so that records from the left table will populate regardless of whether there's a corresponding record in the right table. The query is fine after log, but something seems to be preventing the leftjoin to work as intended. Here's the code:

` ->baseQuery(function (Builder $query, array $data): Builder {
$query->from('subjects')
->leftJoin('subject_allocations', function ($join) use ($data) {
$join->on('subjects.id', '=', 'subject_allocations.subject_id');

                            if (isset($data['school_class_id']) && isset($data['section_id'])) {
                                $join->where('subject_allocations.school_class_id', $data['school_class_id'])
                                    ->where('subject_allocations.section_id', $data['section_id']);
                            }
                        });

                    Log::info($query->toSql(), $query->getBindings());

                    return $query;
                })`
vocal caveBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

wet plank
#

hi

wet plank
#

hello

nimble tundra
#

Try modifyQueryUsing() instead.

wet plank
#

this solved the issue

->query(function (Builder $query, array $data): Builder { // No need for where conditions here return $query; })