outhebox/nova-sortable

This package is abandoned and no longer maintained. No replacement package was suggested.

This Laravel Nova package allows you to reorder models in a Nova resource's index view using drag & drop.

Installs: 410

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 24

Language:Vue

1.1.3.1 2020-01-20 13:08 UTC

This package is auto-updated.

Last update: 2021-05-10 18:57:16 UTC


README

Latest Version on Packagist Total Downloads

This Laravel Nova package allows you to reorder models in a Nova resource's index view using drag & drop.

Uses Spatie's eloquent-sortable under the hood.

Requirements

  • Laravel Nova >= 2.6.0

Features

  • Drag & drop reorder within one page of resources
  • Move to start and end arrows (makes item first/last)
  • Localization
  • Everything from eloquent-sortable

Screenshots

Sortable

Installation

Install the package in a Laravel Nova project via Composer:

# Install package
composer require outhebox/nova-sortable

Usage

Add an order field to the model using Laravel migrations:

# Add order field with default value
Schema::table('some_model', function (Blueprint $table) {
  $table->integer('sort_order');
});
DB::statement('UPDATE some_model SET sort_order = id');

Implement the Spatie's eloquent-sortable interface and apply the trait:

use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;

class MyModel extends Eloquent implements Sortable
{
  use SortableTrait;

  public $sortable = [
    'order_column_name' => 'sort_order',
    'sort_when_creating' => true,
  ];

  ...
}

Apply HasSortableRows trait from this package on the Resource:

use OptimistDigital\NovaSortable\Traits\HasSortableRows;

class MyResource extends Resource
{
  use HasSortableRows;

  ...
}

Localization

The translation file(s) can be published by using the following publish command:

php artisan vendor:publish --provider="OptimistDigital\NovaSortable\ToolServiceProvider" --tag="translations"

You can add your translations to resources/lang/vendor/nova-sortable/ by creating a new translations file with the locale name (ie et.json) and copying the JSON from the existing en.json.

Credits

License

Nova Sortable is open-sourced software licensed under the MIT license.