PHP code example of lee-to / moonshine-kanban-board-resource

1. Go to this page and download the library: Download lee-to/moonshine-kanban-board-resource library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lee-to / moonshine-kanban-board-resource example snippets


use Leeto\MoonShineKanBan\Resources\KanBanResource;

class TaskResource extends KanBanResource
{
    protected string $title = 'title';

    protected string $sortColumn = 'sorting';

    protected ?string $description = 'description'; // Card description field (optional)

    // ... fields, model, etc ...

    protected function pages(): array
    {
        return [
            TaskIndexPage::class,
            FormPageContract::class,
        ];
    }

    public function statuses(): \Illuminate\Support\Collection
    {
        return Status::query()
            ->orderBy('sorting')
            ->pluck('name', 'id');
    }

    public function foreignKey(): string
    {
        return 'status_id';
    }

    // ...
}

final class TaskIndexPage extends IndexPage
{
    protected function modifyListComponent(ComponentContract $component): ComponentContract
    {
        return KanBanComponent::make($this->getResource(), $this->getResource()->getItems());
    }
}

use Leeto\MoonShineKanBan\DTOs\KanbanItem;

public function getItems(): iterable
{
    $items = new Collection;

    foreach (parent::getItems() as $task) {
        $item = KanbanItem::make(
            id: $task->id,
            title: $task->title,
            status: $this->foreignKey(),
        )
            ->setModel($task)
            ->setSubtitle(str($task->description)->limit(50)->value())
            //->setThumbnail(asset('images/template.jpg'))
            ->addLabel(fake()->word(), 'red')
            ->addLabel(fake()->word(), 'green')
            ->setUser(
                avatar: asset('images/template.jpg'),
                name: $task->user->name,
            )
            ->addMeta('user', $task->user->name)
            ->addMeta('chat-bubble-left', (string) random_int(0, 100))
            ->addMeta('users', (string) random_int(0, 50))
            ->setButtons([])
        ;

        $items->push($item);
    }

    return $items;
}

/**
 * Action buttons for cards in kanban
 */
protected function buttons(): ListOf
{
    return [
        // ActionButton
    ];
}