我有这个查询
$organisationUserNotifications = OrganisationUserNotification::
whereHas('user',function($user){
$user->where('status',STATUS_ACTIVE);
})
->orWhere('new_comment',ORGANISATION_NOTIFICATION_ACTIVE)
->orWhere('new_review',ORGANISATION_NOTIFICATION_ACTIVE)
->orWhere('new_salary',ORGANISATION_NOTIFICATION_ACTIVE)
->get();
此查询获取拥有new_comment->1
或new_review->1
或new_salary->1
我有user
表
id
name
status
1
|us_1
|0
2
|us_2
|1
3
|us_3
|1
和notification
表
id
new_comment
new_review
new_salary
1
|0
|1
|1
2
|1
|0
|1
3
|1
|0
|1
此查询获取所有行,因为用户1具有status
0或new_review
1
请任何想法
如果用户处于活动状态,如果没有leftjoin
where
答案 0 :(得分:0)
$organisationUserNotifications = OrganisationUserNotification::
whereHas('user',function($user){
$user->where('status',STATUS_ACTIVE);
})
->where(function($query){
$query->orWhere('new_comment',ORGANISATION_NOTIFICATION_ACTIVE);
$query->orWhere('new_review',ORGANISATION_NOTIFICATION_ACTIVE);
$query->orWhere('new_salary',ORGANISATION_NOTIFICATION_ACTIVE);
})
->get();