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
Column Sortable

Column Sortable Laravel Package

kyslik/column-sortable

kyslik/column-sortable adds easy column sorting to Laravel 5.5–8 apps. Use Blade helpers to generate sortable links, configure sortable columns, and sort by related hasOne/belongsTo fields, with override and alias options for custom queries.

View on GitHub
Deep Wiki
Context7

Package for handling column sorting in Laravel 6.x

Frequently asked questions about Column Sortable
How do I install kyslik/column-sortable in a Laravel application?
Pull the package in with Composer using a version constraint that matches your Laravel release, then let Laravel's package auto-discovery register the service provider. Publish the configuration file with the vendor:publish command if you want to customise icons or defaults. After that, add the Sortable trait and a $sortable allowlist array to each model you want to sort.
Which Laravel versions does kyslik/column-sortable support?
The README headline still says Laravel 5.5-8 while its own table of contents says 5.5-10, and release notes show newer major lines for current Laravel versions. Treat the documentation as drifted and pin your constraint from the package's composer.json instead. In practice, v6.x covers older applications, v7.x targets Laravel 9 and above on PHP 8.0+, and newer majors track the latest Laravel releases.
How do I make a column sortable with the @sortablelink Blade directive?
Add the Sortable trait and a protected $sortable array listing the allowed columns to your Eloquent model. In your controller, call sortable() on the query builder before paginating. In the Blade view, replace plain table headers with @sortablelink('column_name', 'Label') so each header renders a link that toggles direction.
Can column-sortable sort by a relationship column?
Only hasOne and belongsTo relations are supported out of the box, configured through your $sortable and $sortableAs arrays. Anything else, such as hasMany or nested relations, requires a hand-written xxxSortable($query, $direction) override that pushes the join logic into the model. Note that sorting by two different relations in a single query will throw an error.
Why do I get ColumnSortableException errors or 500s from the sort parameter?
The sort value comes straight from the query string, so a malformed or tampered URL makes the package throw ColumnSortableException with codes 0, 1 or 2. Without a handler those bubble up as HTTP 500 responses and burn error budget on trivial requests. Catch the exception locally or register a global handler that returns a 400, redirects, or falls back to the default ordering.
How do I sort by an aliased column or a withCount value?
The package supports aliasing so a sortable key can map to a different select expression, which is also the documented route for withCount columns. You define the alias in the model's sortable configuration and add the matching select or withCount call to your query. The Blade link then references the alias rather than the raw database column.
Does kyslik/column-sortable work with Inertia, Vue, React or an API-only backend?
Only partly. The Blade directive is dead weight outside server-rendered views, so SPA and API front-ends get value only from the sortable() query scope. It does not provide client-side table sorting at all. If you have both surfaces, standardise on the scope plus an explicit allowlist and build link generation and validation separately.
How do I change the sort icons or fix missing arrow glyphs?
Icon behaviour is driven by Font Awesome class suffixes in the package config, and the classes differ between Font Awesome 4 and 5. If you never publish the config, silent defaults apply and you can end up with missing glyphs. Publish the configuration, pick the matching FA version, and confirm Font Awesome is already a dependency you ship.
Is kyslik/column-sortable still maintained, and what are the alternatives?
Maintenance is shallow rather than absent: framework compatibility commits are largely automated laravel-shift pull requests, which keeps the package installable but signals low human feature investment. It is a single-primary-maintainer project on a small, easily forkable codebase, so fork-and-patch is a credible fallback. If you need richer filtering or query-string APIs, a dedicated query builder package or a small hand-rolled orderBy with an allowlist are common alternatives.
Does column-sortable hurt performance if I forget to define $sortable?
Yes, and silently. When the $sortable allowlist is missing, the package falls back to Schema::hasColumn(), which adds a schema query on every request instead of being resolved once. Nothing warns you about it, so the cost only shows up as latency at scale. Make an explicit allowlist a written internal convention, and confirm your sortable columns are indexed.
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.
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels