0

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'));

}

and this is my database: enter image description here

But when I run it I get this result:

enter image description here

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?

2 Answers 2

2

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();
Sign up to request clarification or add additional context in comments.

Comments

0

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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.