naxon / nova-field-sortable
A Laravel Nova field.
Installs: 265 184
Dependents: 1
Suggesters: 0
Security: 0
Stars: 60
Watchers: 1
Forks: 23
Open Issues: 5
Requires
- php: >=7.1.0
- laravel/nova: *
- spatie/eloquent-sortable: ^3.4
README
Description
This field adds reordering functionality to your resource's index using the awesome eloquent-sortable package by the great people of Spatie.
Requrements
- Laravel 5.6+ with Nova.
- spatie/eloquent-sortable (If not already installed, this package will install if for you and all you have to do is follow the installation instructions).
Installation
This package can be installed through Composer.
composer require naxon/nova-field-sortable
Usage
- Follow the usage instructions on the eloquent-sortable repository to make your model sortable.
- Use the
Naxon\NovaFieldSortable\Concerns\SortsIndexEntries
trait in your Nova Resource. - Add a public static property called
$defaultSortField
to your resource, containing your sorting column (I recomment adding it in your mainapp/Nova/Resource.php
file). - Add the
Naxon\NovaFieldSortable\Sortable
field to your Nova Resourcefields
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 Naxon\NovaFieldSortable\Concerns\SortsIndexEntries; use Naxon\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 naxond@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.