aiman/nest-tool 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

aiman/nest-tool

最新稳定版本:v1.0.0

Composer 安装命令:

composer require aiman/nest-tool

包简介

A Laravel Nova resource tool.

README 文档

README

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

统计信息

  • 总下载量: 1.91k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-21