如何使用laravel eloquent编写这个条件
SQL
select count(id) from fight where status = 'finished' and (user1 = 1 or user2 = 1)
Laravel(未完成):
Fight::where('user1','=',$uid)->orWhere('user2', '=', $uid)->count('id');
谢谢
最佳答案
这应该可以完成工作:
Fight::whereStatus('finished')->where(function($q) use ($uid) {
$q->where('user1',$uid)->orWhere('user2', $uid);
})->count('id');
编辑
回复评论:
Fight::whereIn('status', ['finished', 'cancelled'])->where(function($q) use ($uid) {
$q->where('user1',$uid)->orWhere('user2', $uid);
})->count('id');
关于mysql - 拉拉维尔 4 : multiple where with or in eloquent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26777361/