christophe-44-27/nova-field-sortable

A Laravel Nova field to easily sort records in your tables.

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/christophe-44-27/nova-field-sortable

dev-main 2025-06-05 15:57 UTC

This package is not auto-updated.

Last update: 2025-10-24 15:49:55 UTC


README

Latest Version on Packagist Total Downloads

Description

This field adds reordering functionality to your resource's index using the awesome eloquent-sortable package by the great people of Spatie.

screenshot

Requrements

Installation

This package can be installed through Composer.

composer require christophe-44-27/nova-field-sortable

Usage

  1. Follow the usage instructions on the eloquent-sortable repository to make your model sortable.
  2. Use the CodeWithChristophe\NovaFieldSortable\Concerns\SortsIndexEntries trait in your Nova Resource.
  3. Add a public static property called $defaultSortField to your resource, containing your sorting column (I recomment adding it in your main app/Nova/Resource.php file).
  4. Add the CodeWithChristophe\NovaFieldSortable\Sortable field to your Nova Resource fields method, using a label and your primary key column.

Example

<?php

namespace App\Nova;

use Laravel\Nova\Fields\ID;
use Illuminate\Http\Request;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Fields\Text;
use CodeWithChristophe\NovaFieldSortable\Concerns\SortsIndexEntries;
use CodeWithChristophe\NovaFieldSortable\Sortable;

class Page extends Resource
{
    use SortsIndexEntries;
    
    public static $defaultSortField = 'sort_order';
    
    /**
     * Get the fields displayed by the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),
            
            Text::make('Title'),
            
            Sortable::make('Order', 'id')
                ->onlyOnIndex(),
        ];
    }
}

Security

If you discover any security related issues, please email christophelablancherie@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.