我得到了產品和庫存表;如何訂購另一張表通過在Laravel中急於加載
產品
id int
name varchar
created_at timestamp
股
id int
name varchar
product_id varchar
created_at timestamp
產品型號
public function validStock() {
return $this->hasMany('Stock')->where('quantity', '>', 10);
}
如果都有科瑞ed_at,如何通過股市的created_at訂購,我已經嘗試了兩種方法,它不是工作
Product::with('validStock')->orderBy('validStock.created_at', 'DESC');
Product::with(array('validStock' => function($q) {
$q->orderBy('created_at', 'DESC');
}));
https://github.com/fico7489/laravel-eloquent-join – fico7489