[英]Laravel , how to select data if relationship condition is true
我有这个查询
$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,请问如何验证用户是否处于活动状态的其他where
(无leftjoin)
好的,如果有人需要,我就找到了解决方案
$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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.