【问题标题】:Laravel , how to select data if relationship condition is trueLaravel,如果关系条件为真,如何选择数据
【发布时间】:2017-07-06 16:46:28
【问题描述】:

我有这个问题

$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

idnamestatus
1| us_1| 0
2| us_2| 1
3| us_3| 1

notification

idnew_commentnew_reviewnew_salary
1| 0| 1 | 1
2| 1| 0 | 1
3| 1| 0 | 1

此查询获取所有行,因为用户 1 有 status 0 或 new_review 1 请有任何想法 如果用户处于活动状态,如何验证其他where,没有leftjoin

【问题讨论】:

    标签: php jquery laravel model-view-controller laravel-5


    【解决方案1】:

    好的,如果有人需要,我找到了解决方案

    $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();
    

    【讨论】:

      猜你喜欢
      • 2014-04-01
      • 1970-01-01
      • 2020-04-23
      • 1970-01-01
      • 1970-01-01
      • 2017-01-24
      • 2013-11-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多