Coder Social home page Coder Social logo

muhghazaliakbar / nova-field-sortable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from naxon/nova-field-sortable

0.0 0.0 0.0 67 KB

Adds sorting functionality to the Laravel Nova's index resource

License: MIT License

Vue 37.04% JavaScript 5.54% CSS 0.28% PHP 57.14%

nova-field-sortable's Introduction

Laravel Nova Sortable Field

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 naxon/nova-field-sortable

Usage

  1. Follow the usage instructions on the eloquent-sortable repository to make your model sortable.
  2. Use the Naxon\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 Naxon\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 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'),
        ];
    }
}

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

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

nova-field-sortable's People

Contributors

naxon avatar ragingdave avatar emanuelecoppola avatar muhghazaliakbar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.