Aleks Per Aleks Per - 1 year ago 103
PHP Question

Laravel eloquent give wrong result

I have this code:

public function inbox()
$id = Auth::user()->id;
$bids = Bid::where('user_id',$id)
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?

Answer Source

you are getting this unexpected error because of orWhere,you can do like this way

$bids = Bid::where('user_id',$id)
                       ->where(function ($query) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download