Laravel Community Tools by Tighten
Laravel Nova icon Nova Packages

Readme

Nova Order Field

Latest Version on Packagist Total Downloads

Description

A field that adds reordering functionality to your Laravel Nova resource's index using the eloquent-sortable package by Spatie.

Demo

Demo

Installation

This package can be installed through Composer.

composer require michielkempen/nova-order-field

Usage

  1. Follow the usage instructions on the eloquent-sortable repository to make your model sortable.
  2. Add the MichielKempen\NovaOrderField\Orderable trait to your Nova Resource.
  3. Add a public static property called $defaultOrderField to your resource, containing your order column.
  4. Add the OrderField to your Nova Resource fields method.

Grouping

If your model/table has a grouping field (usually a foreign key): id, user_id, title, order_column and you'd like the above methods to take it into considerations, you can create a buildSortQuery method at your model:

public function buildSortQuery()
{
    return static::query()->where('user_id', $this->user_id);
}

This will restrict the calculations to fields value of the model instance.

Example

use MichielKempen\NovaOrderField\Orderable;
use MichielKempen\NovaOrderField\OrderField;

class Page extends Resource
{
    use Orderable;
    
    public static $defaultOrderField = 'order';
    
    public function fields(Request $request)
    {
        return [
            OrderField::make('Order'),
        ];
    }
}

Screenshots

Reviews

By denisvasilievclarity on July 26, 2024

Doesn't work at all.

By Eugene van der Merwe on April 29, 2020

Really wonderful implementation. Save me hours / days of schlep. Well done. Update: Also using this one now: https://novapackages.com/packages/optimistdigital/nova-sortable

Back to Top
Added 6 years ago
Last updated 4 Years Ago
Version 2.1.0
Nova Version ^2.0|^3.0
Composer
michielkempen/nova-order-field
GitHub stars 59
Packagist downloads 231,819

Favorites

15 users favorited

Rating

3.10
(out of 5)
★★★★★
★★★★
★★★
★★
7 ratings

Brought to you by Tighten

Issues/Feature Requests Stats Package Ideas