Reputation: 1639
I have this code:
public function inbox()
{
$id = Auth::user()->id;
$bids = Bid::where('user_id',$id)
->where('status','0')
->orWhere('status','4')
->latest()->get();
dd($bids);
return view('rooms.inbox', compact('bids'));
}
But when I run it I get this result:
my Auth user id is 8 but I get wrong results? Why?
ALso when i try ;
$bids = Auth::user()->bids()->get();
then I get right results///
What is problem?
Upvotes: 0
Views: 698
Reputation: 2285
You need to use Advanced Where Clauses
Your Query should like,
$bids = Bid::where('user_id',$id)
->where(function ($query) {
$query->where('status', '0')
->orWhere('status', '4');
})->latest()->get();
Upvotes: 0
Reputation: 5445
you are getting this unexpected error because of orWhere,you can do like this way
$bids = Bid::where('user_id',$id)
->where(function ($query) {
$query->where('status','0')
->orWhere('status','4');
})
->latest()->get();
Upvotes: 2