我有这段代码,只过滤那些有大约customerRewards
个与某个客户有关的公司.whereHas()
过滤器工作正常,但customerRewards from $的结果也包含了不同客户ID的项目.
$companies = Company::with(['customerRewards']) // This is the problem
->has('customerRewards')
->whereHas('customerRewards', function(Builder $q) use ($customer) {
$q->where('customer_id', $customer->id); // This works as expected
})
->get();
如何过滤$与Collection ?