### Install filament-kanban Package
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Install the package using Composer.
```bash
composer require mokhosh/filament-kanban
```
--------------------------------
### Install Filament Kanban Package
Source: https://context7.com/mokhosh/filament-kanban/llms.txt
Install the package via Composer and publish its CSS assets using the provided Artisan command.
```bash
composer require mokhosh/filament-kanban
php artisan filament-kanban:install
```
--------------------------------
### Generate Kanban Board Page
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Use the artisan command to generate a new Kanban board page, providing a starting point for customization.
```bash
php artisan make:kanban UsersKanbanBoard
```
--------------------------------
### Override Kanban Board Views
Source: https://context7.com/mokhosh/filament-kanban/llms.txt
Customize individual board view templates by setting static properties within your `KanbanBoard` class. This example shows how to override the default views for the board, header, record, status, and scripts.
```php
use Mokhosh\FilamentKanban\Pages\KanbanBoard;
class TaskKanbanBoard extends KanbanBoard
{
protected static string $model = \App\Models\Task::class;
protected static string $statusEnum = \App\Enums\TaskStatus::class;
// Override individual templates (defaults shown)
protected static string $view = 'filament-kanban::kanban-board'; // outer wrapper
protected static string $headerView = 'filament-kanban::kanban-header'; // column title
protected static string $recordView = 'filament-kanban::kanban-record'; // each card
protected static string $statusView = 'filament-kanban::kanban-status'; // column container
protected static string $scriptsView = 'filament-kanban::kanban-scripts'; // SortableJS init
}
```
--------------------------------
### Custom Kanban Record View
Source: https://context7.com/mokhosh/filament-kanban/llms.txt
Create a custom Blade view for individual Kanban cards. This example defines a `kanban-card.blade.php` view that displays the task title, assignee, and labels.
```blade
{{-- $record is the full Eloquent model instance --}}
{{ $record->title }}
{{ $record->assignee?->name ?? 'Unassigned' }}
@foreach($record->labels as $label)
{{ $label->name }}
@endforeach
```
--------------------------------
### Customize Kanban Status Title
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Override the `getTitle` method to customize how the status title is retrieved. This example uses Laravel's translation helper.
```php
public function getTitle(): string
{
return __($this->label());
}
```
--------------------------------
### Configure In-Card Edit Modal Form
Source: https://context7.com/mokhosh/filament-kanban/llms.txt
Override `getEditModalFormSchema()` to define the fields for the edit modal. This example shows how to add a title, description, and an assignee select field.
```php
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Mokhosh\FilamentKanban\Pages\KanbanBoard;
class TaskKanbanBoard extends KanbanBoard
{
protected static string $model = \App\Models\Task::class;
protected static string $statusEnum = \App\Enums\TaskStatus::class;
// Set to true to remove the modal entirely
public bool $disableEditModal = false;
// Modal appearance
protected string $editModalTitle = 'Edit Task';
protected string $editModalWidth = '3xl'; // Filament modal width
protected bool $editModalSlideOver = false; // true = slide-over panel
protected string $editModalSaveButtonLabel = 'Save Changes';
protected string $editModalCancelButtonLabel = 'Discard';
// Define which form fields appear in the modal
protected function getEditModalFormSchema(null|int|string $recordId): array
{
return [
TextInput::make('title')->required()->maxLength(255),
RichEditor::make('description')->columnSpanFull(),
Select::make('assignee_id')
->relationship('assignee', 'name')
->searchable(),
];
}
// Control what data fills the form (default: full toArray())
protected function getEditModalRecordData(int|string $recordId, array $data): array
{
return \App\Models\Task::with('assignee')->find($recordId)->toArray();
}
// Custom save logic (default: $model->update($data))
protected function editRecord(int|string $recordId, array $data, array $state): void
{
$task = \App\Models\Task::find($recordId);
$task->update([
'title' => $data['title'],
'description' => $data['description'],
'assignee_id' => $data['assignee_id'] ?? null,
]);
}
}
```
--------------------------------
### Testing Kanban Board with Pest and Livewire
Source: https://context7.com/mokhosh/filament-kanban/llms.txt
Utilize Livewire component methods exposed by the package for robust testing. Simulate user interactions like moving cards between statuses or editing records via modals using `livewire()` from `pestphp/pest-plugin-livewire`.
```php
use App\Enums\TaskStatus;
use App\Models\Task;
use App\Filament\Pages\TaskKanbanBoard;
use function Pest\Laravel\actingAs;
use function Pest\Livewire\livewire;
// Assert status columns are rendered
it('shows all status columns', function () {
actingAs(User::factory()->create())
->get(TaskKanbanBoard::getUrl())
->assertSeeInOrder(['Backlog', 'In Progress', 'Review', 'Done']);
});
// Simulate dragging a card to a new status column
it('updates status when card is moved', function () {
$task = Task::factory()->create(['status' => TaskStatus::Backlog]);
livewire(TaskKanbanBoard::class)
->dispatch('status-changed', $task->id, TaskStatus::Done->value, [], []);
expect($task->fresh()->status)->toBe(TaskStatus::Done);
});
// Simulate editing a card via the modal
it('edits a record through the modal', function () {
$task = Task::factory()->create(['title' => 'Old Title']);
livewire(TaskKanbanBoard::class)
->call('recordClicked', $task->id, [])
->assertDispatched('open-modal', id: 'kanban--edit-record-modal')
->set('editModalFormState.title', 'Updated Title')
->call('editModalFormSubmitted')
->assertDispatched('close-modal', id: 'kanban--edit-record-modal');
expect($task->fresh()->title)->toBe('Updated Title');
});
// Assert the modal can be disabled
it('hides the edit modal when disabled', function () {
livewire(TaskKanbanBoard::class)
->set('disableEditModal', true)
->assertDontSee('Edit Record');
});
```
--------------------------------
### Publish Kanban Views
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Use the `php artisan vendor:publish` command with the `filament-kanban-views` tag to publish the view files for customization.
```bash
php artisan vendor:publish --tag="filament-kanban-views"
```
--------------------------------
### Publish Kanban Assets
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Publish the package assets to ensure correct styling.
```bash
php artisan filament-kanban:install
```
--------------------------------
### Scaffold a Kanban Board Page
Source: https://context7.com/mokhosh/filament-kanban/llms.txt
Use the `make:kanban` Artisan command to generate a new Kanban board page class. This command scaffolds a class that extends `KanbanBoard` and pre-configures the necessary model and status Enum properties.
```bash
php artisan make:kanban TaskKanbanBoard
```
--------------------------------
### Publish Kanban Views
Source: https://context7.com/mokhosh/filament-kanban/llms.txt
Use the `vendor:publish` Artisan command to publish all Filament Kanban views for global customization. Published views are located in `resources/views/vendor/filament-kanban/`.
```bash
# Publish all views for global customization
php artisan vendor:publish --tag="filament-kanban-views"
```
--------------------------------
### Run Package Tests
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Execute the package's test suite using Composer. Ensure all tests pass to verify package integrity.
```bash
composer test
```
--------------------------------
### Extend KanbanBoard for Custom Task Board
Source: https://context7.com/mokhosh/filament-kanban/llms.txt
Extend the `KanbanBoard` class to define the Eloquent model, status enum, and customize record retrieval and querying for a task board.
```php
use App\Enums\TaskStatus;
use App\Models\Task;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
use Mokhosh\FilamentKanban\Pages\KanbanBoard;
class TaskKanbanBoard extends KanbanBoard
{
// Required: the Eloquent model driving the board
protected static string $model = Task::class;
// Required: the status enum (must use IsKanbanStatus)
protected static string $statusEnum = TaskStatus::class;
// Optional: which model attribute holds the card title (default: 'title')
protected static string $recordTitleAttribute = 'title';
// Optional: which model attribute holds the status (default: 'status')
protected static string $recordStatusAttribute = 'status';
// Optional: navigation icon in the Filament sidebar
protected static ?string $navigationIcon = 'heroicon-o-view-columns';
// Optional: restrict/filter which records appear on the board
protected function records(): Collection
{
return Task::where('assigned_to', auth()->id())
->ordered() // from spatie/eloquent-sortable
->get();
}
// Optional: customize the Eloquent query (e.g. with eager loading)
protected function getEloquentQuery(): Builder
{
return Task::query()->with(['assignee', 'labels']);
}
}
```
--------------------------------
### Configure Kanban Board Model
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Override the static `$model` property in your Kanban board class to specify the Eloquent model that provides the records for the board.
```php
protected static string $model = User::class;
```
--------------------------------
### Register Filament Kanban Plugin
Source: https://context7.com/mokhosh/filament-kanban/llms.txt
Register the FilamentKanbanPlugin in your Filament panel provider configuration to enable its functionality.
```php
use Mokhosh\FilamentKanban\FilamentKanbanPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
FilamentKanbanPlugin::make(),
]);
}
```
--------------------------------
### Eloquent Model Configuration for Spatie Sortable
Source: https://context7.com/mokhosh/filament-kanban/llms.txt
Configure your Eloquent model to implement Spatie's Sortable trait for drag-and-drop ordering within the Kanban board. Ensure the `SortableTrait` is used and define the `sortable` property with `order_column_name` and `sort_when_creating` options.
```php
use Illuminate\Database\Eloquent\Model;
use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;
use App\Enums\TaskStatus;
class Task extends Model implements Sortable
{
use SortableTrait;
protected $guarded = [];
protected $casts = [
'status' => TaskStatus::class,
];
public $sortable = [
'order_column_name' => 'order_column',
'sort_when_creating' => true,
];
}
```
--------------------------------
### Reference Custom Record View
Source: https://context7.com/mokhosh/filament-kanban/llms.txt
After creating a custom record view, reference it in your `KanbanBoard` class by setting the `static $recordView` property to the path of your Blade file.
```php
protected static string $recordView = 'tasks.kanban-card';
```
--------------------------------
### Generated Kanban Board Page Class
Source: https://context7.com/mokhosh/filament-kanban/llms.txt
The generated Kanban board page class extends `KanbanBoard` and requires static properties for the Eloquent model and the status Enum to be defined.
```php
get();
}
```
--------------------------------
### Change Navigation Icon
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Set the static `$navigationIcon` property to change the icon used in the navigation menu for the Kanban board.
```php
protected static ?string $navigationIcon = 'heroicon-o-document-text';
```
--------------------------------
### Derive Status Columns from Database
Source: https://context7.com/mokhosh/filament-kanban/llms.txt
Override the `statuses()` method to define Kanban board columns based on database records instead of an enum. This allows for dynamic status management.
```php
use Illuminate\Support\Collection;
use Mokhosh\FilamentKanban\Pages\KanbanBoard;
class ProjectKanbanBoard extends KanbanBoard
{
protected static string $model = \App\Models\Card::class;
protected static string $statusEnum = \App\Enums\CardStatus::class;
// Override with database-driven columns
protected function statuses(): Collection
{
return \App\Models\BoardColumn::ordered()->get()->map(fn ($col) => [
'id' => $col->slug,
'title' => $col->label,
]);
}
}
```
--------------------------------
### Handle Card Moved Between Columns
Source: https://context7.com/mokhosh/filament-kanban/llms.txt
Implement `onStatusChanged()` to execute custom logic when a card is moved between status columns. This includes updating the record's status and optionally triggering notifications.
```php
use Mokhosh\FilamentKanban\Pages\KanbanBoard;
class TaskKanbanBoard extends KanbanBoard
{
protected static string $model = \App\Models\Task::class;
protected static string $statusEnum = \App\Enums\TaskStatus::class;
public function onStatusChanged(
int|string $recordId,
string $status,
array $fromOrderedIds, // IDs ordered in the source column after removal
array $toOrderedIds // IDs ordered in the destination column after insertion
): void {
$task = \App\Models\Task::find($recordId);
$task->update(['status' => $status]);
// Persist sort order in both affected columns
\App\Models\Task::setNewOrder($toOrderedIds);
// Custom side-effect: notify assignee
$task->assignee?->notify(new \App\Notifications\TaskStatusChanged($task));
}
}
```
--------------------------------
### Configure Kanban Board Status Enum
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Override the static `$statusEnum` property to define the enum that manages the statuses for your Kanban board.
```php
protected static string $statusEnum = UserStatus::class;
```
--------------------------------
### Override Specific Kanban Views
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Override individual view properties like `$view`, `$headerView`, `$recordView`, `$statusView`, and `$scriptsView` to customize specific parts of the Kanban board's rendering.
```php
protected static string $view = 'filament-kanban::kanban-board';
protected static string $headerView = 'filament-kanban::kanban-header';
protected static string $recordView = 'filament-kanban::kanban-record';
protected static string $statusView = 'filament-kanban::kanban-status';
protected static string $scriptsView = 'filament-kanban::kanban-scripts';
```
--------------------------------
### Define Custom Kanban Statuses
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Override the `kanbanCases` method in your Enum to return a subset of cases for the Kanban board. This controls which statuses are displayed.
```php
public static function kanbanCases(): array
{
return [
static::CaseOne,
static::CaseThree,
];
}
```
--------------------------------
### Customize Kanban Statuses
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Override the `statuses` method if you do not use an Enum for statuses or require special logic for retrieving them. This method should return a collection of status definitions.
```php
protected function statuses(): Collection
{
return collect([
['id' => 'user', 'title' => 'User'],
['id' => 'admin', 'title' => 'Admin'],
]);
}
```
--------------------------------
### Handle Status Change Event
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Implement the `onStatusChanged` method to define the behavior when a record is moved between statuses. This method receives the record ID, new status, and ordered IDs of records in the source and destination columns.
```php
public function onStatusChanged(int|string $recordId, string $status, array $fromOrderedIds, array $toOrderedIds): void
{
User::find($recordId)->update(['status' => $status]);
User::setNewOrder($toOrderedIds);
}
```
--------------------------------
### Handle Sort Change Event
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Implement the `onSortChanged` method to define the behavior when a record is reordered within the same status column. This method receives the record ID, the current status, and the new order of record IDs within that status.
```php
public function onSortChanged(int|string $recordId, string $status, array $orderedIds): void
{
User::setNewOrder($orderedIds);
}
```
--------------------------------
### Define Enum for Kanban Statuses
Source: https://context7.com/mokhosh/filament-kanban/llms.txt
Apply the IsKanbanStatus trait to a string-backed PHP Enum to define statuses for the Kanban board. Override kanbanCases() to filter visible cases and getTitle() to customize column labels.
```php
use Mokhosh\FilamentKanban\Concerns\IsKanbanStatus;
enum TaskStatus: string
{
use IsKanbanStatus;
case Backlog = 'backlog';
case InProgress = 'in_progress';
case Review = 'review';
case Done = 'done';
// Only show a subset of cases on the board
public static function kanbanCases(): array
{
return [
static::InProgress,
static::Review,
static::Done,
];
}
// Customize the column title label
public function getTitle(): string
{
return match($this) {
static::InProgress => 'In Progress',
static::Review => 'In Review',
static::Done => '✅ Done',
};
}
}
// Usage — produces a Collection for the board:
// [
// ['id' => 'in_progress', 'title' => 'In Progress'],
// ['id' => 'review', 'title' => 'In Review'],
// ['id' => 'done', 'title' => '✅ Done'],
// ]
TaskStatus::statuses();
```
--------------------------------
### Customize Edit Form Submission
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Override the `editRecord` method to customize the logic executed when the edit form is submitted. The `data` array contains form input.
```php
protected function editRecord(int|string $recordId, array $data, array $state): void
{
Model::find($recordId)->update([
'phone' => $data['phone']
]);
}
```
--------------------------------
### Handle Card Reordered Within a Column
Source: https://context7.com/mokhosh/filament-kanban/llms.txt
Implement `onSortChanged()` to handle custom logic when a card is reordered within the same status column. This typically involves updating the sort order of records.
```php
use Mokhosh\FilamentKanban\Pages\KanbanBoard;
class TaskKanbanBoard extends KanbanBoard
{
protected static string $model = \App\Models\Task::class;
protected static string $statusEnum = \App\Enums\TaskStatus::class;
public function onSortChanged(
int|string $recordId,
string $status, // The column where the sort happened
array $orderedIds // All IDs in that column in their new order
): void {
\App\Models\Task::setNewOrder($orderedIds);
}
}
```
--------------------------------
### Customize Edit Modal Appearance
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Override properties like `$editModalTitle`, `$editModalWidth`, `$editModalSaveButtonLabel`, `$editModalCancelButtonLabel`, and `$editModalSlideOver` to customize the modal's appearance and behavior.
```php
protected string $editModalTitle = 'Edit Record';
protected string $editModalWidth = '2xl';
protected string $editModalSaveButtonLabel = 'Save';
protected string $editModalCancelButtonLabel = 'Cancel';
protected bool $editModalSlideOver = true;
```
--------------------------------
### Define Kanban Status Enum
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Use the IsKanbanStatus trait to easily define statuses for your Kanban board. This trait provides a `statuses` method for transforming enum cases.
```php
use Mokhosh\FilamentKanban\Concerns\IsKanbanStatus;
enum UserStatus: string
{
use IsKanbanStatus;
case User = 'User';
case Admin = 'Admin';
}
```
--------------------------------
### Define Edit Modal Form Schema
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Override the `getEditModalFormSchema` method to define the form schema for the edit modal. You have access to the record ID.
```php
protected function getEditModalFormSchema(int|string|null $recordId): array
{
return [
TextInput::make('title'),
];
}
```
--------------------------------
### Change Record Status Attribute
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Set the static `$recordStatusAttribute` property to specify which model attribute is used as the status for records.
```php
protected static string $recordStatusAttribute = 'status';
```
--------------------------------
### Change Record Title Attribute
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Set the static `$recordTitleAttribute` property to specify which model attribute is used as the title for records.
```php
protected static string $recordTitleAttribute = 'title';
```
--------------------------------
### Disable Edit Modal
Source: https://github.com/mokhosh/filament-kanban/blob/main/README.md
Set the `$disableEditModal` property to `true` to disable the edit modal that appears when clicking on records.
```php
public bool $disableEditModal = false;
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.