PHP code example of asignua / filament-kanban

1. Go to this page and download the library: Download asignua/filament-kanban 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/ */

    

asignua / filament-kanban example snippets


use Asignua\FilamentKanban\KanbanPlugin;

$panel->plugin(KanbanPlugin::make());

use Asignua\FilamentKanban\Concerns\IsKanbanStatus;
use Filament\Support\Contracts\HasColor;
use Filament\Support\Contracts\HasIcon;
use Filament\Support\Contracts\HasLabel;

enum TaskStatus: string implements HasColor, HasIcon, HasLabel
{
    use IsKanbanStatus;

    case Todo = 'todo';
    case Doing = 'doing';
    case Done = 'done';

    public function getLabel(): string { return ucfirst($this->value); }
    public function getColor(): string { return match ($this) { self::Todo => 'gray', self::Doing => 'warning', self::Done => 'success' }; }
    public function getIcon(): string { return 'heroicon-m-bolt'; }
}

use Asignua\FilamentKanban\Pages\KanbanBoard;

class TasksBoard extends KanbanBoard
{
    protected static string $model = Task::class;

    protected static string $statusEnum = TaskStatus::class;

    protected static string $recordStatusAttribute = 'status';   // default

    protected static string $recordTitleAttribute = 'title';     // default

    protected static ?string $recordSortAttribute = 'position';  // where the manual order is stored; null = not stored
}

protected static string $recordStatusAttribute = 'stage_id';

protected function statuses(): Collection
{
    return Stage::query()->orderBy('position')->get()->map(fn (Stage $stage): array => [
        'id' => (string) $stage->id,
        'title' => $stage->name,
        'value' => $stage->id,
        'color' => $stage->color,   // optional: a Filament colour name
        'icon' => null,             // optional
        'collapsed' => false,       // optional
    ]);
}

class TasksKanban extends \Asignua\FilamentKanban\Pages\KanbanResourcePage
{
    protected static string $resource = TaskResource::class;

    protected static string $statusEnum = TaskStatus::class;
}

// TaskResource::getPages(): 'kanban' => TasksKanban::route('/kanban')

use Filament\Forms\Components\Textarea;

protected function columnTransitionSchema(string $from, string $to): ?array
{
    return $to === 'lost' ? [Textarea::make('lost_reason')->

protected ?int $recordsPerColumn = 25;

protected function recordsPerColumn(KanbanColumn $column): ?int
{
    return in_array($column->id, ['won', 'lost'], true) ? 25 : null;
}

protected function recordTitle(Model $record): string;                       // default: the title attribute
protected function recordDescription(Model $record): ?string;                // grey line under the title
protected function recordBadges(Model $record, KanbanColumn $column): array; // [['label' => 'Overdue', 'color' => 'danger', 'icon' => 'heroicon-m-clock']]
protected function recordExtras(Model $record, KanbanColumn $column): array; // free markup (Htmlable)
protected function recordUrl(Model $record): ?string;                        // the card becomes a link, no modal
protected function recordRelations(): array;                                 // eager loads

protected function getEditModalFormSchema(int|string|null $recordId): array
{
    return [TextInput::make('title')->?->update($data);   // default: forceFill($data)->save()
}

protected string $editModalTitle = 'Edit task';
protected string $editModalWidth = '2xl';
protected bool $editModalSlideOver = true;
protected string $editModalSaveButtonLabel = 'Save';
protected string $editModalCancelButtonLabel = 'Cancel';
public bool $disableEditModal = false;

protected static string $toolbarView = 'my-board.toolbar';
protected static string $headerView = 'my-board.header';   // a column header
protected static string $statusView = 'my-board.column';
protected static string $recordView = 'my-board.card';
protected static string $scriptsView = 'my-board.scripts'; // empty by default
protected string $view = 'my-board.page';

use Asignua\FilamentKanban\Support\Realtime;

Realtime::authorizeUsing(fn ($user, string $board): bool => $user->canSeeProjectBoards());
bash
php artisan make:kanban TasksBoard --model="App\Models\Task" --enum="App\Enums\TaskStatus"
bash
php artisan install:broadcasting --reverb && php artisan reverb:start