[英]How to skip a relationship and use other relationship based on where clause in a query using same query data in laravel 8
我想在查詢中使用 if else 但使用 where 子句使用此查詢的數據
如果您想有條件地預先加載一個關系,您可以在查詢中使用when(condition, callback)
。
$query = YourModel::query()
->when($something == true, function ($query) {
$query->with('relationship')
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.