Reputation: 135
Hi I want to build query with eloquent.
DB name friends with 4 rows id,friend1, friend2 and accepted.
So I want to create something like this
$count = Friends::where('friend1', '=', '$user1')->and('accepted', '=', '1')->orWhere('friend2', '=', '$user2')->and('accepted', '=', '1')->get();
Should I replace 'and' with 'where'. And if I do that it will work normally as with 'and'?
Upvotes: 0
Views: 400
Reputation: 87719
I think this is a clear way of looking at it:
$count = Friends::where(function($query){
$query->where('friend1', '=', '$user1')
->where('accepted', '=', '1')
})->orWhere(function($query){
$query->where('friend2', '=', '$user2')
->where('accepted', '=', '1')
})->get();
Upvotes: 1