我想加入到表NotificationTypes與 UserEnabledNotificationTypesId在NotificationTypesId列UserEnabledNotifications,只對這些行deleted_at的列NotificationTypes表為空。我試過如下。但它不是對表null中deleted_at列 的值進行排序NotifocationTypes。任何解決方案?
UserEnabledNotifications::with('userNotications', function ($query){
$query->whereNull('deleted_at');
})->select('userId','notificationTypesId')->get();
用戶啟用通知
public function userNotifications(){
return $this->belongsTo(NotificationTypes::class, 'notificationTypesId','id');
}
uj5u.com熱心網友回復:
您需要將 with/closure 作為陣列鍵/值對傳遞
UserEnabledNotifications::with(['userNotifications' => function ($query){
$query->whereNull('deleted_at');
}])->select('userId','notificationTypesId')->get();
要僅獲取具有未洗掉的userNotifications 的 UserEnabledNotifications,您需要whereHas
UserEnabledNotifications::whereHas('userNotifications', function(Builder $query) {
$query->whereNull('deleted_at');
})
->with(['userNotifications' => function($query) {
$query->whereNull('deleted_at');
}])->select('userId', 'notificationTypesId')->get();
uj5u.com熱心網友回復:
嘗試使用此查詢將列替換為實際列。無需檢查 的NULL值deleted_at。它將默認檢查NULL.
UserEnabledNotifications::with(['userNotifications', function ($query){
$query->orderBy('column', 'ASC');
}])->select('userId','notificationTypesId')->get();
讓我知道結果。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/317442.html
標籤:php 拉拉维尔 雄辩 laravel-8 查询生成器
上一篇:帶模式的PHP格式字串
