我正在做一个项目,我们在其中保存用户的活动和他的隐私设置。我想根据用户的隐私设置获取其活动。因此,如果用户将其gpa设置为私有,则我的查询不应获取与gpa相关的用户活动。我当前的查询如下:
UserActivity::with(['User' => function ($q) {
$q->with(['avatar' => function ($q2) {
$q2->select(['id', 'image']);
}])
->select(['id', 'first_name', 'last_name', 'profile_picture']);
}, 'User.PrivacySetting'])
->whereHas('User.PrivacySetting', function($q3) {
$q3->where('gpa', '!=', PrivacySetting::PRIVACY_STATUS_NO_ONE)
->orWhere('cv', '=', PrivacySetting::PRIVACY_STATUS_NO_ONE)
->orWhere('groups', '!=', PrivacySetting::PRIVACY_STATUS_NO_ONE)
->orWhere('phone', '!=', PrivacySetting::PRIVACY_STATUS_NO_ONE)
->orWhere('courses', '!=', PrivacySetting::PRIVACY_STATUS_NO_ONE)
->orWhere('notes', '!=', PrivacySetting::PRIVACY_STATUS_NO_ONE)
->orWhere('classifieds', '!=', PrivacySetting::PRIVACY_STATUS_NO_ONE)
->orWhere('checkin_event', '!=', PrivacySetting::PRIVACY_STATUS_NO_ONE);
})
->orderBy('id', 'desc');