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:Jump to solution
this solved the issue
`->query(function (Builder $query, array $data): Builder { // No need for where conditions here return $query;...
`->query(function (Builder $query, array $data): Builder { // No need for where conditions here return $query;...
3 Replies