Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lee-to/moonshine-tree-resource
https://github.com/lee-to/moonshine-tree-resource
Last synced: 5 days 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 (over 1 year ago)
- Default Branch: 2.x
- Last Pushed: 2024-10-19T21:07:42.000Z (24 days ago)
- Last Synced: 2024-10-20T08:56:17.459Z (23 days ago)
- Language: PHP
- Size: 121 KB
- Stars: 12
- 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 | Trix |
|-------------|------|
| 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::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
```php
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()),
];
}
}
```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;
}
```