- MoonShine v2.0+
composer require lee-to/moonshine-tree-resource
Example usage with tree
use Leeto\MoonShineTree\Resources\TreeResource;
class CategoryResource extends TreeResource
{
// Required
protected string $column = 'title';
protected string $sortColumn = 'sorting';
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';
}
public function sortKey(): string
{
return 'sorting';
}
// ...
}
And add component
namespace App\MoonShine\Pages;
use Leeto\MoonShineTree\View\Components\TreeComponent;
use MoonShine\Pages\Crud\IndexPage;
class CategoryTreePage extends IndexPage
{
protected function mainLayer(): array
{
return [
...$this->actionButtons(),
TreeComponent::make($this->getResource()),
];
}
}
Just a sortable usage
use Leeto\MoonShineTree\Resources\TreeResource;
class CategoryResource extends TreeResource
{
// Required
protected string $column = 'title';
protected string $sortColumn = 'sorting';
// ... fields, model, etc ...
public function treeKey(): ?string
{
return null;
}
public function sortKey(): string
{
return 'sorting';
}
// ...
}
public function itemContent(Model $item): string
{
return 'Custom content here';
}
public function wrapable(): bool
{
return false;
}
public function sortable(): bool
{
return false;
}