https://github.com/lee-to/moonshine-tree-resource
https://github.com/lee-to/moonshine-tree-resource
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/lee-to/moonshine-tree-resource
- Owner: lee-to
- License: mit
- Created: 2023-05-17T13:33:03.000Z (about 2 years ago)
- Default Branch: 2.x
- Last Pushed: 2024-12-18T07:59:51.000Z (6 months ago)
- Last Synced: 2025-03-26T09:01:44.302Z (2 months ago)
- Language: PHP
- Size: 129 KB
- Stars: 16
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
## MoonShine sortable tree resource
### Requirements
- MoonShine v3.0+
### Support MoonShine versions
| MoonShine | TreeResource |
|-------------|------|
| 2.0+ | 1.0+ |
| 3.0+ | 2.0+ |### Installation
```shell
composer require lee-to/moonshine-tree-resource
```### Get started
Example usage with tree
```php
use Leeto\MoonShineTree\Resources\TreeResource;class CategoryResource extends TreeResource
{
// Required
protected string $column = 'title';protected string $sortColumn = 'sorting';
protected function pages(): array
{
return [
CategoryTreePage::class,
FormPage::class,
DetailPage::class,
];
}// ... fields, model, etc ...
public function treeKey(): ?string
{
return 'parent_id';
}public function sortKey(): string
{
return 'sorting';
}// ...
}
```And add component
```php
namespace App\MoonShine\Pages;use Leeto\MoonShineTree\View\Components\TreeComponent;
use MoonShine\Laravel\Pages\Crud\IndexPage;class CategoryTreePage extends IndexPage
{
protected function mainLayer(): array
{
return [
...$this->getPageButtons(),
TreeComponent::make($this->getResource()),
];
}
}
```Or modify index component from resource
```php
protected string $sortColumn = 'sorting';public function modifyListComponent(ComponentContract $component): ComponentContract
{
return TreeComponent::make($this);
}
```
Just a sortable usage```php
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
```php
public function itemContent(Model $item): string
{
return 'Custom content here';
}
```### Turn off sortable or wrapable
```php
public function wrapable(): bool
{
return false;
}public function sortable(): bool
{
return false;
}
```