繁体   English   中英

Laravel,如果关系条件为真,如何选择数据

[英]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->1new_review->1new_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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM