Skip to main content
Back to packages
647 GitHub stars

Kyslik/column-sortable

View on GitHub

Description

Package for handling column sorting

Use Sortable trait inside your Eloquent model(s). Define $sortable array (see example code below).

NOTE: Scheme::hasColumn() is run only when $sortable is not defined - less DB hits per request.

use Kyslik\ColumnSortable\Sortable;
 
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
use Authenticatable, CanResetPassword, Sortable;
...
 
public $sortable = ['id',
'name',
'email',
'created_at',
'updated_at'];
...
}

You're set to go.

Sortable trait adds Sortable scope to the models so you can use it with paginate.

Blade Extension

There is a blade extension for you to use @sortablelink()

@sortablelink('column', 'Title', ['parameter' => 'smile'], ['rel' => 'nofollow'])

Recent Courses on Laravel Daily

Roles and Permissions in Laravel 13

14 lessons
57 min

How to Build Laravel 13 API From Scratch

30 lessons
1 h 23 min

How to Structure Laravel 13 Projects

16 lessons
1 h 32 min read