djnew/moonshine-nested-set
Composer 安装命令:
composer require djnew/moonshine-nested-set
包简介
Tree resource for moonshine
关键字:
README 文档
README
The resource tree of this package is based on the kalnoy/nestedset
Requirements
- MoonShine v2.0+
Installation
composer require djnew/moonshine-nested-set
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 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
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 you only need to fix the tree to fill
_lft and _rgt columns:
MyModel::fixTree();
Additional content
public function itemContent(Model $item): string { return 'Custom content here'; }
Turn off sortable or wrapable
public function wrapable(): bool { return false; }
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')]), ]; } }```
djnew/moonshine-nested-set 适用场景与选型建议
djnew/moonshine-nested-set 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.27k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 05 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「moonshine」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 djnew/moonshine-nested-set 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 djnew/moonshine-nested-set 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 djnew/moonshine-nested-set 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
User permissions for MoonShine
Field for repeating groups of fields for MoonShine
Task scheduling extension for MoonShine
Project builder for MoonShine
Ace editor for MoonShine
Scout support for MoonShine
统计信息
- 总下载量: 1.27k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-23