PHP code example of novius / laravel-nova-order-nestedset-field

1. Go to this page and download the library: Download novius/laravel-nova-order-nestedset-field 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/ */

    

novius / laravel-nova-order-nestedset-field example snippets


use Kalnoy\Nestedset\NodeTrait;
use Novius\LaravelNovaOrderNestedsetField\Traits\Orderable;

class Foo extends Model {
    use NodeTrait;
    use Orderable;
    
    public function getLftName()
    {
        return 'left';
    }
    
    public function getRgtName()
    {
        return 'right';
    }
    
    public function getParentIdName()
    {
        return 'parent';
    }
}


use Novius\LaravelNovaOrderNestedsetField\OrderNestedsetField;

class FooResource extends Resource
{       
    public function fields(Request $request)
    {
        return [
            OrderNestedsetField::make('Order'),
        ];
    }
    
    /**
     * @param \Illuminate\Database\Eloquent\Builder $query
     * @param array $orderings
     * @return \Illuminate\Database\Eloquent\Builder
     */
    protected static function applyOrderings($query, array $orderings)
    {
        return $query->orderBy('left', 'asc');
    }
}


    protected function getScopeAttributes()
    {
        return ['menu_id'];
    }

return [
    ...

    'cache_enabled' => true,
];

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Kalnoy\Nestedset\NodeTrait;
use Novius\LaravelNovaOrderNestedsetField\Traits\Orderable;

class Foo extends Model 
{
    use NodeTrait;
    use Orderable;

    public static function boot()
    {
        parent::boot();

        if (config('nova-order-nestedset-field.cache_enabled', false)) {
            static::created(function (Theme $model) {
                $model->clearOrderableCache();
            });

            static::updated(function (Theme $model) {
                $model->clearOrderableCache();
            });

            static::deleted(function (Theme $model) {
                $model->clearOrderableCache();
            });
        }
    }
}
sh
php artisan vendor:publish --provider="Novius\LaravelNovaOrderNestedsetField\OrderNestedsetFieldServiceProvider" --tag="config"
sh
php artisan vendor:publish --provider="Novius\LaravelNovaOrderNestedsetField\OrderNestedsetFieldServiceProvider" --tag="lang"