Level 75
Look over this query and see how it was derived: https://laracasts.com/discuss/channels/eloquent/orderby-computed-related-attribute
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi all,
I'm trying to sortBy or orderBy the sum of amount from my groupBy...this is what I have in my controller
$expenses = $project->expenses()->groupBy('vendor_id')->get();
This returns the correct info but I'm not sure how to sort it so that the first result is the largest sum of AMOUNT for each vendor. Amount is stored in Expenses table together with vendor_id. Thank you in advance for any help!
Please or to participate in this conversation.