我有带有 id、privacy(0,1,2)、comment_body
列的评论表
我正在使用 Larvael 4.2.x
Eloquent 来获取结果。我想要得到的是来自一个用户的所有带有0和1隐私的评论。
我尝试了什么?
选项 1
$user = User::find(1);
//query will give me comment for privacy = 0
$comment_for_user = $user->comments()->where('privacy','0');
选项 2
//this wont return anything
$comment_for_user = $user->comments()->where('privacy','0')
->where('privacy',1);
选项 3
//return the result but gets post form all users
$comment_for_user = $user->comments()->where('privacy','0')
->Orwhere('privacy',1);
感谢您的帮助。
最佳答案
您可以使用whereIn
。
$comment_for_user = $user->comments()->whereIn('privacy', array(0, 1))->get();
您可以在 documentation 找到更多有用的方法.
关于php - Laravel Eloquent WHERE 和 AND,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30557908/