lee-to / moonshine-tree-resource
Tree resource for moonshine
Installs: 2 854
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 2
Forks: 0
Open Issues: 1
Requires
- php: ^8.0|^8.1|^8.2
- ext-curl: *
- ext-json: *
Conflicts
- moonshine/moonshine: <2.0
README
Requirements
- MoonShine v2.0+
Installation
composer require lee-to/moonshine-tree-resource
Get started
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'; } // ... }
Additional content
public function itemContent(Model $item): string { return 'Custom content here'; }
Turn off sortable or wrapable
public function wrapable(): bool { return false; } public function sortable(): bool { return false; }