/** * @param User $actor * @param Builder $query */ public function find(User $actor, Builder $query) { // Hide discussions which have tags that the user is not allowed to see. $query->whereNotExists(function ($query) use($actor) { return $query->select(new Expression(1))->from('discussions_tags')->whereIn('tag_id', Tag::getIdsWhereCannot($actor, 'viewDiscussions'))->where('discussions.id', new Expression('discussion_id')); }); }
/** * 扩展查询,获取排除通识素质课的课程数据 * @author FuRongxin * @date 2016-03-09 * @version 2.0 * @param \Illuminate\Database\Eloquent\Builder $query 查询对象 * @return \Illuminate\Database\Eloquent\Builder 查询对象 */ public function scopeExceptGeneral($query) { return $query->whereNotExists(function ($query) { $query->from('pk_kczy AS a')->whereRaw('t_a.nd = t_pk_kczy.nd AND t_a.xq = t_pk_kczy.xq AND t_a.zsjj = t_pk_kczy.zsjj AND t_a.kcxh = t_pk_kczy.kcxh')->wherePt('T')->where(function ($query) { $query->whereXz('W')->orWhere('xz', '=', 'I')->orWhere('xz', '=', 'Y')->orWhere('xz', '=', 'Q'); }); }); }
/** * @param User $actor * @param Builder $query */ public function find(User $actor, Builder $query) { // Hide discussions which have tags that the user is not allowed to see. $query->whereNotExists(function ($query) use($actor) { return $query->select(new Expression(1))->from('discussions_tags')->whereIn('tag_id', Tag::getIdsWhereCannot($actor, 'viewDiscussions'))->where('discussions.id', new Expression('discussion_id')); }); // Hide discussions with no tags if the user doesn't have that global // permission. if (!$actor->hasPermission('viewDiscussions')) { $query->has('tags'); } }