Created
July 26, 2020 03:03
-
-
Save zhanang19/83378a988ca5d8fe9017b6a12342c3d7 to your computer and use it in GitHub Desktop.
Laravel order by relationship aggregates example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$popularSerials = Serial::addSelect([ | |
'total_views' => Video::selectRaw('sum(views) as total_views') | |
->whereColumn('serial_id', 'serials.id') | |
->groupBy('serial_id') | |
]) | |
->orderBy('total_views') | |
->get(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment