2016-04-29 44 views
0

我有兩個型號Bill & Order, 我可以通過獲得Orders記錄:雄辯的支點:如何做選擇列Laravel 5.1

$orders = $bill->orders; 

但我想用選擇這樣的:

$orders = $bill->orders->select([ 
          'orders.*',        
          \DB::raw('sum(orders.quantity) as qty'), 
          \DB::raw('sum(orders.price) as total')        
          ]) 
          ->groupBy('article_id'); 

我得到這個錯誤:

Method select does not exist. 

請任何人都可以幫助我,謝謝!

回答

0

我得到了解決:d

只要編輯這樣說:

$orders = $bill->orders()->select([ 
         'orders.*',        
         \DB::raw('sum(orders.quantity) as qty'), 
         \DB::raw('sum(orders.price) as total')        
         ]) 
         ->groupBy('article_id')->get(); 

和它的罰款:)))