This works for me in Laravel 5.3, using your example:
Hackathon::withCount('participants')->orderBy('participants_count', 'desc')->paginate(10);
This way it is ordered on the query and the pagination works nicely.
More Related Contents:
- Laravel one to many relation with a one to one relation
- How to do this in Laravel, subquery where in
- Laravel 5.2 – Use a String as a Custom Primary Key for Eloquent Table becomes 0
- Laravel $q->where() between dates
- Eloquent many-to-many-to-many – how to load distant relation easily
- Eloquent groupBy make “SQLSTATE[42000]” with valid SQL query in Laravel 5.3
- How to Create Multiple Where Clause Query Using Laravel Eloquent?
- Get the Last Inserted Id Using Laravel Eloquent
- Bulk Insertion in Laravel using eloquent ORM
- Laravel 5 PDOException Could Not Find Driver
- Laravel, sync() – how to sync an array and also pass additional pivot fields?
- Laravel 4: how to “order by” using Eloquent ORM [duplicate]
- How to exclude certains columns while using eloquent
- How to alias the name of a column in Eloquent
- belongsToMany relationship in Laravel across multiple databases
- How Can I Set the Default Value of a Timestamp Column to the Current Timestamp with Laravel Migrations?
- How to Make Laravel Eloquent “IN” Query?
- Update without touching timestamps (Laravel)
- Laravel Cannot delete or update a parent row: a foreign key constraint fails
- laravel collection to array
- Base table or view not found: 1146 Table Laravel 5
- Laravel Eloquent sort by relation table column
- Eloquent Parent-Child relationship on same model
- How can I query raw via Eloquent?
- Mysql InnoDB engine in Laravel
- A __construct on an Eloquent Laravel Model
- How to get last insert id in Eloquent ORM laravel
- PHP Laravel: No connection could be made because the target machine actively refused it
- Check if laravel model got saved or query got executed
- find in set in laravel ? example