So I have two models Product
and ProductPriceHistories
Product
hasMany ProductPriceHistories
and it's basically a daily price of a product.
I have one slight problem, when I try to find the lowest price of the product I'm returned multiple of the same products
because of the join finding multiple prices for the product.
This is my query:
$products = ProductPriceHistory::orderBy(
'product_price_histories.price',
$request->get('direction')
)
->with('products')
->select('products.*')
->paginate(16);
I have tried various ways, but essentially I need to get the products in the order of most expensive or cheapest based on $request->get('direction')
If it's not possible to do it in Eloquent I will do it in a DB:Raw but surely it's me not knowing how to do it properly.
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2fZCG7r
via IFTTT
Aucun commentaire:
Enregistrer un commentaire