I have read multiple question about this subject but didn't work for me. Link
I have two model product and price between product and price exist hasMany relationship. in product model:
public function price()
{
return $this->hasMany("App\Price","product_id","id");
}
I want sort product collection by price. inside my price model i have price property. this is my code for sort products collection by price relation and price property.
$products=Product::find($id);
$products->load(['price'=>function($q){
$q->orderBy('price', 'asc');
}]);
dd($products->toArray());
please help me.Thanks.