Laravel Community Tools by Tighten
Laravel Nova icon Nova Packages

Readme

Nest Tool

This Nova Package allow you to nest items in hierarchy level.

image

Installation

composer require aiman/nest-tool

Example Migration Schema

class CreateTopicsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('topics', function (Blueprint $table) {
            $table->id();
            $table->text('topic');
            $table->text('slug')->nullable();
            $table->integer('order')->default(1);
            $table->integer('parent_id')->nullable();
            $table->timestamps();
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('topics');
    }
}

Usage

In order to use the nest tool, it requires a model to use which includes a order column, parent column, amd the display name to be shown in each item. Example is shown above

use Aiman\ThaanaTextField\ThaanaTextField;

    /**
     * Get the fields displayed by the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),
            
            //other fields
            
            NestTool::make()
             ->usingModel(\App\Models\Topic::class)
             ->slug('slug')
             ->orderColumn('order')
             ->parentColumn('parent_id')
             ->displayName('topic')
             ->disable(false)
        ];
    }

Relationship

the model which is entered into usingModel() function should have this relationship

function parent(){
    return $this->belongsTo('App\Models\Topic', 'parent_id');
}

function children(){
    return $this->hasMany(self::class, 'parent_id')->orderBy('order')->with('children');
}

Model

This function requires the model in which nest tool uses

NestTool::make()->usingModel(\App\Models\Topic::class)

Slug

This function requires the slug field to be displayed. By default it is slug

NestTool::make()->slug('slug')

Order

This function requires the order column name in the model class above which is used for ordering. By default it is order

NestTool::make()->orderColumn('order')

Parent Id

This function requires the parent column name in the model class above which is used for nesting items under a parent item. By default it is parent_id

NestTool::make()->parentColumn('parent_id')

Topic

This function requires the display name's column name in the model class above which is used to display in each item. By default it is topic

NestTool::make()->displayName('topic')

Important

This package is tested for nova 2.0+ Latest tested on nova v3.6.0

Screenshots

Reviews

By JurjenRoels on October 11, 2020

Really Like this package. It would be even greater if you could use this on the index page and if the nested items could be collapseable.

By Arthur Minasyan on July 27, 2020

Amazing job. Thank you so much. Easy to use. Highly recommended.

Back to Top
Added 5 years ago
Last updated 5 Years Ago
Version v1.0.0
Composer
aiman/nest-tool
GitHub stars 2
Packagist downloads 1,923

Favorites

10 users favorited

Rating

5.00
(out of 5)
★★★★★
★★★★
★★★
★★
2 ratings

Brought to you by Tighten

Issues/Feature Requests Stats Package Ideas