1 回答

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊
我認(rèn)為您需要使用whereHas(反過(guò)來(lái)使用exists查詢)。如果你只使用 with,你仍然會(huì)得到每一個(gè)Order。您只過(guò)濾哪些相關(guān)Review或Product急切加載。
使用whereHasor whereExists,您首先過(guò)濾Order模型,然后加載關(guān)系。
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 關(guān)注
- 122 瀏覽
添加回答
舉報(bào)