PHP code example of pixelcreation / nova-field-sortable

1. Go to this page and download the library: Download pixelcreation/nova-field-sortable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pixelcreation / nova-field-sortable example snippets




namespace App\Nova;

use Laravel\Nova\Fields\ID;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Fields\Text;
use PixelCreation\NovaFieldSortable\Concerns\SortsIndexEntries;
use PixelCreation\NovaFieldSortable\Sortable;

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