Currently I am retrieving product results for a category like this:
$products = $category->products()->with('prices')->paginate(12);
A category is related to a product via a 'category_product' table and the product's prices are stored in a 'prices' table (as each product might have more than one price associated with it.
I would like to sort the results by price (the prices() relation is sorted this way on the model).
Is it possible to do this? I have tried ->orderBy('prices.amount') and variants. Can't get my head around it.
Thank you.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community