PHP code example of hadyfayed / filament-workflow-canvas
1. Go to this page and download the library: Download hadyfayed/filament-workflow-canvas 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/ */
hadyfayed / filament-workflow-canvas example snippets
use HadyFayed\WorkflowCanvas\Models\Workflow;
class WorkflowBuilder extends Component
{
public Workflow $workflow;
public array $canvasData = [];
public function mount(Workflow $workflow)
{
$this->workflow = $workflow;
$this->canvasData = $workflow->canvas_data ?? [];
}
public function updatedCanvasData()
{
$this->workflow->update(['canvas_data' => $this->canvasData]);
}
public function render()
{
return view('livewire.workflow-builder');
}
}
use HadyFayed\WorkflowCanvas\Forms\Components\WorkflowCanvasField;
// In your Filament Resource
WorkflowCanvasField::make('canvas_data')
->reactive() // Enable real-time React-PHP state sync
->lazy() // Load component when visible (performance optimization)
->enableAutoSave() // Auto-save workflow changes
->showMinimap() // Show workflow minimap
->enableFullscreen() // Allow fullscreen editing
->nodeTypes(config('workflow-canvas.node_types'))
->onWorkflowChange(fn($state) => $this->processWorkflow($state));
use HadyFayed\WorkflowCanvas\Widgets\WorkflowStatsWidget;
// In your Filament Panel
class WorkflowStatsWidget extends ReactWidget
{
protected string $componentName = 'WorkflowStatsWidget';
public function getData(): array
{
return $this->getWorkflowStats(); // Data automatically shared with React
}
}
use HadyFayed\WorkflowCanvas\Events\WorkflowStarted;
use HadyFayed\WorkflowCanvas\Events\WorkflowCompleted;
use HadyFayed\WorkflowCanvas\Events\WorkflowFailed;
// Listen for workflow events
Event::listen(WorkflowStarted::class, function ($event) {
Log::info('Workflow started', ['workflow_id' => $event->workflow->id]);
});