1 回答

TA贡献1865条经验 获得超7个赞
我认为您需要使用whereHas(反过来使用exists查询)。如果你只使用 with,你仍然会得到每一个Order。您只过滤哪些相关Review或Product急切加载。
使用whereHasor whereExists,您首先过滤Order模型,然后加载关系。
App\Order::where(function ($query) {
$query->where('user_id', auth()->id())->orWhereHas('producto', function ($producto) {
$producto->where('user_id', auth()->id());
});
})
->whereHas('review', function ($review) {
$review->whereNotNull('buyer_rate')->orWhereNotNull('seller_rate');
})
->with([
'review',
'producto' => function ($producto) {
$producto->select('id', 'user_id', 'nombre', 'precio', 'descripcion');
},
])
->get();
auth()->id()auth()->user()->id与或相同Auth::user()->id
- 1 回答
- 0 关注
- 125 浏览
添加回答
举报