Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Eloquent Sorts

Laravel Eloquent Sorts Laravel Package

plin-code/laravel-eloquent-sorts

Add flexible, safe sorting to Laravel Eloquent models. Define allowed sortable columns, map request parameters to query ordering, set defaults, and keep controllers clean with a simple reusable trait for consistent, validated sorting.

View on GitHub
Deep Wiki
Context7

Reusable Eloquent sorts for Laravel: order by a relation column, by relation count, or by a custom enum order, with adapters for spatie/laravel-query-builder.

Frequently asked questions about Laravel Eloquent Sorts
How do I order a Laravel Eloquent query by a related model column?
Use an Eloquent sort that targets the relation and column, then apply it to the query builder. The package is designed to wrap relation-column ordering so you do not have to hand-write the join or subquery each time. Confirm the exact sort class name and signature in the package README before wiring it into your query.
How can I sort Laravel results by relationship count?
The package includes a sort for ordering by the number of related records, such as comments or likes. It typically translates the sort into a withCount plus orderBy, so the count is available on the query. Check the README for the expected relation name parameter and whether the count alias is configurable.
Can I order Eloquent results by a custom enum order?
Yes, the package is described as supporting a custom enum order sort. That means you can define the sequence of enum cases and have the query return rows in that sequence rather than alphabetical or database order. Review the README for how the enum class and case order are supplied.
How does laravel-eloquent-sorts work with spatie/laravel-query-builder?
The package ships adapters for spatie/laravel-query-builder, so its sorts can be used through QueryBuilder's allowed sorts flow. You register or allow the sort and let QueryBuilder apply it from the request. The adapter layer is what connects the package's sort definitions to Spatie's sort interface.
How do I install plin-code/laravel-eloquent-sorts?
Install it with Composer using composer require plin-code/laravel-eloquent-sorts. Laravel package discovery should register the service provider if one is required. After installation, publish any config file only if the README instructs you to.
Which Laravel versions does plin-code/laravel-eloquent-sorts support?
Laravel version support is defined by the package's composer.json constraints, not by the package description. Check the require section on Packagist or in the package metadata before adding it to an existing application. If you are on an older Laravel release, verify compatibility first.
Is this package suitable for production queries?
It is intended for reusable Eloquent sorting, including relation column and relation count sorts. Relation count sorts usually add a withCount subquery, which can be costly on large tables, so review query plans and indexes. Test the generated SQL in your environment before relying on it for high-traffic endpoints.
Can I test the sorts without hitting the database?
You can unit test the sort definitions if the package exposes them as query-builder callbacks or invokable sort classes. For relation-based ordering, integration tests against a test database are usually more reliable because they verify the generated SQL and joins. Use Laravel's database testing helpers and assert the returned order.
What are alternatives to using a package for Eloquent relation sorting?
You can write joins, subqueries, or withCount plus orderBy calls directly in your query builder. spatie/laravel-query-builder also supports custom sorts, so you can implement sorts there without an extra package. This package mainly reduces duplication by packaging common relation and enum ordering patterns.
Is plin-code/laravel-eloquent-sorts actively maintained?
The provided information does not include repository activity, release history, or maintainer details. Check Packagist and the linked repository for recent commits, open issues, and version tags before adopting it. For long-lived projects, confirm that the package supports your Laravel version and has a clear upgrade path.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core