我有一个集合,我想在其中使用whereIn和where,但是我知道whereIn或where可以工作。
我想获得用户ID = [1,2,3,4]且类型= admin的结果。如果用户ID为空,则显示admin的帖子,如果type = admin为null,则在用户ID的基础上显示post,或者如果两者均可用,则显示所有具有用户ID和admin类型的帖子。
这是我的查询:
Post::with('commonContent', 'postLike','user.userDetails','likeCount')
->whereIn('user_id',$user_ids)
->where('type','admin');
答案 0 :(得分:1)
您想要这样吗?
Post::with('commonContent', 'postLike','user.userDetails','likeCount')->whereIn('user_id',$user_ids)->orWhere('type','admin')->get();