2016-05-31 22 views
0

我有這樣的代碼:Laravel侃侃而談給出錯誤的結果

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

} 

,這是我的數據庫: enter image description here

但是當我運行它,我得到這樣的結果:

enter image description here

我的Auth用戶標識是8但我得到錯誤的結果?爲什麼?

我也試過; $bids = Auth::user()->bids()->get();然後我得到正確的結果///

什麼是問題?

回答

1

你得到,因爲orWhere這個意外的錯誤,你可以像這樣

$bids = Bid::where('user_id',$id) 
         ->where(function ($query) { 
         $query->where('status','0') 
         ->orWhere('status','4'); 
         }) 
         ->latest()->get(); 
0

您需要使用Advanced Where Clauses

您的查詢想,

$bids = Bid::where('user_id',$id) 
      ->where(function ($query) { 
       $query->where('status', '0') 
        ->orWhere('status', '4'); 
      })->latest()->get();