crayon/nova-treeview

A Laravel Nova tool.

Installs: 11

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 13

Language:Vue

0.5.2 2021-06-30 09:36 UTC

This package is auto-updated.

Last update: 2024-04-26 15:23:08 UTC


README

Display a model in a Tree View with drag and drop functionality. Useful for category structure.

Setup

Make sure your model you wish to use in the tree structure has the following columns:

parent_id
is_active
order

Add the tool to NovaServiceProvider.php

Category Model Example:

Schema::create('categories', function (Blueprint $table) {
    $table->unsignedInteger('id')->autoIncrement();
    $table->string('title');
    $table->string('slug');
    $table->unsignedInteger('parent_id')->nullable();
    $table->boolean('is_active')->default(true);
    $table->tinyInteger('order')->default(0);
});

Usage

/app/Providers/NovaServiceProvider.php
...
use Day4\TreeView\TreeView;
    ...
    public function tools()
    {
        return [
            ...
            new TreeView([
             // ['NAME_IN_SIDEBAR', 'TABLE_NAME']
                ['Categories', 'categories']
            ])
        ];
    }