F
Filament4mo ago
Mikail

Filament filters my leftJoin

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; })
Solution:
this solved the issue
`->query(function (Builder $query, array $data): Builder { // No need for where conditions here return $query;...
Jump to solution
3 Replies
Mikail
MikailOP4mo ago
hi hello
awcodes
awcodes4mo ago
Try modifyQueryUsing() instead.
Solution
Mikail
Mikail4mo ago
this solved the issue
->query(function (Builder $query, array $data): Builder { // No need for where conditions here return $query; })
Want results from more Discord servers?
Add your server