All Projects → novius → laravel-nova-order-nestedset-field

novius / laravel-nova-order-nestedset-field

Licence: other
Laravel Nova field that make your resources orderable

Programming Languages

PHP
23972 projects - #3 most used programming language
Vue
7211 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to laravel-nova-order-nestedset-field

nova-url-field
A URL input and link field for Laravel Nova
Stars: ✭ 96 (+357.14%)
Mutual labels:  nova, laravel-nova
nova-system-resources
Display the system usage in Laravel-Nova
Stars: ✭ 30 (+42.86%)
Mutual labels:  nova, laravel-nova
nova-horizon-stats
Nova cards for Laravel applications that use Laravel Horizon
Stars: ✭ 31 (+47.62%)
Mutual labels:  nova, laravel-nova
nova-inspire
The best way to connect with your customers is by reaching out and inspiring them. ~ Me
Stars: ✭ 14 (-33.33%)
Mutual labels:  nova, laravel-nova
laravel-nova-visual-composer
Visual Composer for Laravel Nova
Stars: ✭ 15 (-28.57%)
Mutual labels:  nova, laravel-nova
nova-qrcode-field
A Laravel Nova field to generate QR Code
Stars: ✭ 28 (+33.33%)
Mutual labels:  nova, laravel-nova
nova-hidden-field
A Laravel Nova Hidden field.
Stars: ✭ 32 (+52.38%)
Mutual labels:  nova, laravel-nova
nova-sluggable
Slug field for Laravel Nova
Stars: ✭ 40 (+90.48%)
Mutual labels:  nova, laravel-nova
yii2-jstree-widget
jsTree tree widget for yii2
Stars: ✭ 16 (-23.81%)
Mutual labels:  tree
Unity-Visual-Behavior-Tree
Reactive Visual Scripting Behavior Tree Tool for Unity 2018.x+
Stars: ✭ 36 (+71.43%)
Mutual labels:  tree
tree-vue
A lightweight library for handling hierarchical content. With full customizations of items rendering.
Stars: ✭ 25 (+19.05%)
Mutual labels:  tree
Algorithms
Java implementation for Introduction to Algorithms book.
Stars: ✭ 58 (+176.19%)
Mutual labels:  tree
GenealogyTreeInGit
Convert family trees from gedcom format to list of git commands that can be executed to build a family git repository
Stars: ✭ 15 (-28.57%)
Mutual labels:  tree
treelike
A trait to abstract over common tree functionality
Stars: ✭ 33 (+57.14%)
Mutual labels:  tree
nova-mailman
Conveniently route all emails to a local mailbox.
Stars: ✭ 47 (+123.81%)
Mutual labels:  nova
nova-blogify-tool
Create a simple blog in a few seconds. Powered by Laravel Nova.
Stars: ✭ 20 (-4.76%)
Mutual labels:  laravel-nova
ds
🔗 Common Data Structures and Algorithms
Stars: ✭ 40 (+90.48%)
Mutual labels:  tree
gb merkle trees
General balanced binary Merkle trees for Erlang
Stars: ✭ 25 (+19.05%)
Mutual labels:  tree
nova-tabs
Another Laravel Nova Tabs Package
Stars: ✭ 60 (+185.71%)
Mutual labels:  nova
scalable-concurrent-containers
High performance containers and utilities for concurrent and asynchronous programming
Stars: ✭ 101 (+380.95%)
Mutual labels:  tree

Nova Order Field nestedset

Travis Packagist Release Licence

A field that make your resources orderable using the laravel nestedset package.

Requirements

  • PHP >= 8.1
  • Laravel Nova >= 4.0

NOTE: These instructions are for Laravel Nova 4.0. If you are using prior version, please see the previous version's docs.

Installation

composer require novius/laravel-nova-order-nestedset-field

Configuration

Some options that you can override are available.

php artisan vendor:publish --provider="Novius\LaravelNovaOrderNestedsetField\OrderNestedsetFieldServiceProvider" --tag="config"

Usage

Step 1

Use Kalnoy\Nestedset NodeTrait and Novius\LaravelNovaOrderNestedsetField Orderable trait on your model.

Example :

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';
    }
}

Step 2

Add the field to your resource and specify order for your resources.

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');
    }
}

Scoping

Imagine you have Menu model and MenuItems. There is a one-to-many relationship set up between these models. MenuItem has menu_id attribute for joining models together. MenuItem incorporates nested sets. It is obvious that you would want to process each tree separately based on menu_id attribute. In order to do so, you need to specify this attribute as scope attribute:

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

Retrieve more information about usage on official doc.

Performances

You can enable cache to avoid performance issues in case of large tree.

By default cache is disabled.

To use cache you have to enabled it in config file with :

return [
    ...

    'cache_enabled' => true,
];

You have to clear cache on every tree updates with an observer on your Model (or directly in boot method).

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();
            });
        }
    }
}

Override default languages files

Run:

php artisan vendor:publish --provider="Novius\LaravelNovaOrderNestedsetField\OrderNestedsetFieldServiceProvider" --tag="lang"

Lint

Run php-cs with:

composer run-script lint

Contributing

Contributions are welcome! Leave an issue on Github, or create a Pull Request.

Licence

This package is under GNU Affero General Public License v3 or (at your option) any later version.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].