PHPackages                             djnew/moonshine-nested-set - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. djnew/moonshine-nested-set

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

djnew/moonshine-nested-set
==========================

Tree resource for moonshine

0.2.0(3mo ago)01.1k1MITPHPPHP ^8.0|^8.1|^8.2|^8.3|^8.4

Since May 23Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/djnew/moonshine-nested-set)[ Packagist](https://packagist.org/packages/djnew/moonshine-nested-set)[ Docs](https://moonshine-laravel.com)[ RSS](/packages/djnew-moonshine-nested-set/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (5)Used By (0)

MoonShine sortable tree resource
--------------------------------

[](#moonshine-sortable-tree-resource)

> The resource tree of this package is based on the [kalnoy/nestedset](https://github.com/lazychaser/laravel-nestedset)

[![](https://github.com/djnew/moonshine-nested-set/raw/main/art/screenshot.png)](https://moonshine-laravel.com)

### Requirements

[](#requirements)

- MoonShine v2.0+

### Installation

[](#installation)

```
composer require djnew/moonshine-nested-set
```

### Get started

[](#get-started)

Example usage with tree

```
use Djnew\MoonShineNestedSet\Resources\NestedsetResource;

class CategoryResource extends NestedsetResource
{
    // Required
    protected string $column = 'title';

    protected string $model    = Page::class;

    // Custom child relation name
    public string $treeRelationName = 'children';

    // Use pagination
    protected bool $usePagination = true;

    // Show Up/Down element buttons for sort
    public bool $showUpDownButtons = false;

    // Items per page
    protected int $itemsPerPage = 10;

    protected function pages(): array
    {
        return [
            CategoryTreePage::make($this->title()),
            FormPage::make(
                $this->getItemID()
                    ? __('moonshine::ui.edit')
                    : __('moonshine::ui.add')
            ),
            DetailPage::make(__('moonshine::ui.show')),
        ];
    }

    // ... fields, model, etc ...

    public function treeKey(): ?string
    {
        return 'parent_id';
    }

    // ...
}
```

And add component

```
namespace App\MoonShine\Pages;

use Djnew\MoonShineNestedSet\View\Components\NestdSetComponent;
use MoonShine\Pages\Crud\IndexPage;

class CategoryTreePage extends IndexPage
{
    protected function mainLayer(): array
    {
        return [
            ...$this->actionButtons(),
            NestdSetComponent::make($this->getResource()),
        ];
    }
}
```

Add migration to model

```
use Kalnoy\Nestedset\NestedSet;

Schema::create('table', function (Blueprint $table) {
    ...
    NestedSet::columns($table);
});
```

To drop columns:

```
...
use Kalnoy\Nestedset\NestedSet;

Schema::table('table', function (Blueprint $table) {
    NestedSet::dropColumns($table);
});
```

Add trait to model

```
namespace App\Models;

use App\Traits\MoonshineNestedSetTrait;
use Illuminate\Database\Eloquent\Model;

class Page extends Model
{
    use moonshineNestedSetTrait;

    // ...
}
```

### Migrating existing data

[](#migrating-existing-data)

#### Migrating from other nested set extension

[](#migrating-from-other-nested-set-extension)

If your previous extension used different set of columns, you just need to override following methods on your model class:

```
public function getLftName()
{
    return 'left';
}

public function getRgtName()
{
    return 'right';
}

public function getParentIdName()
{
    return 'parent';
}

// Specify parent id attribute mutator
public function setParentAttribute($value)
{
    $this->setParentIdAttribute($value);
}
```

#### Migrating from basic parentage info

[](#migrating-from-basic-parentage-info)

If your tree contains `parent_id` info, you need to add two columns to your schema:

```
$table->unsignedInteger('_lft');
$table->unsignedInteger('_rgt');
```

After [setting up your model](#the-model) you only need to fix the tree to fill `_lft` and `_rgt` columns:

```
MyModel::fixTree();
```

### Additional content

[](#additional-content)

```
public function itemContent(Model $item): string
{
    return 'Custom content here';
}
```

### Turn off sortable or wrapable

[](#turn-off-sortable-or-wrapable)

```
public function wrapable(): bool
{
    return false;
}
```

### Use async reload tree resource

[](#use-async-reload-tree-resource)

```
namespace App\MoonShine\Pages;

use Djnew\MoonShineNestedSet\View\Components\NestdSetComponent;
use MoonShine\Pages\Crud\IndexPage;

class CategoryTreePage extends IndexPage
{
    protected function mainLayer(): array
    {
        return [
            ...$this->actionButtons(),
            Fragment::make(
                [
                    NestdSetComponent::make($this->getResource())
                        ->setFragmentName('fragment-name')
                ]
            )->name('fragment-name')
            ->updateAsync(['page' => request()->get('page')]),
        ];
    }
}```
```

###  Health Score

43

—

FairBetter than 90% of packages

Maintenance85

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~202 days

Total

4

Last Release

108d ago

PHP version history (2 changes)0.0.6PHP ^8.0|^8.1|^8.2|^8.3

0.1.0PHP ^8.0|^8.1|^8.2|^8.3|^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/3a6c37228e57a782b5e38b1ad007f9ec059554a051acf0255feac3dd3ef10539?d=identicon)[djnew](/maintainers/djnew)

---

Top Contributors

[![djnew](https://avatars.githubusercontent.com/u/886244?v=4)](https://github.com/djnew "djnew (2 commits)")[![Siesta](https://avatars.githubusercontent.com/u/7994849?v=4)](https://github.com/Siesta "Siesta (2 commits)")

---

Tags

moonshine

### Embed Badge

![Health badge](/badges/djnew-moonshine-nested-set/health.svg)

```
[![Health](https://phpackages.com/badges/djnew-moonshine-nested-set/health.svg)](https://phpackages.com/packages/djnew-moonshine-nested-set)
```

###  Alternatives

[dev-lnk/moonshine-builder

Project builder for MoonShine

254.8k](/packages/dev-lnk-moonshine-builder)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
