Closed wonder95 closed 1 year ago
Thanks to Larry AI at Laracasts, I found out that I just needed to add whereHas()
to my query
use Illuminate\Database\Eloquent\Builder;
use Spatie\QueryBuilder\AllowedFilter;
use Spatie\QueryBuilder\QueryBuilder;
return Inertia::render('TreasuryReport', [
'payments' => QueryBuilder::for(Payment::class)
->with('dues.user')
->allowedFields('dues.user.first_name', 'dues.user.last_name')
->allowedFilters([
AllowedFilter::exact('mode'),
AllowedFilter::callback('name', function (Builder $query, $value) {
$query->whereHas('dues.user', function (Builder $query) use ($value) {
$query->where('first_name', 'like', "%{$value}%")
->orWhere('last_name', 'like', "%{$value}%");
});
})
])
->orderBy('payment_date', 'desc')
->paginate(15)
->withQueryString()
]);
I am attempting to do some filtering using a multi-level nested relationship (User-> Dues ->Payment is the model hierarchy), like so.
but I get the following error
From what I read in the docs and this past issue, this should work.
Am I doing something wrong, or is this indeed a bug?