PHP code example of tomatophp / filament-workflows
1. Go to this page and download the library: Download tomatophp/filament-workflows 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/ */
use TomatoPHP\FilamentWorkflows\Traits\InteractsWithWorkflow;
class Order extends Model
{
use InteractsWithWorkflow;
}
use TomatoPHP\FilamentWorkflows\Facades\FilamentWorkflows;
use TomatoPHP\FilamentWorkflows\Services\Contracts\WorkflowModel;
FilamentWorkflows::model([
WorkflowModel::make('Orders')->model(\App\Models\Order::class),
]);
use TomatoPHP\FilamentWorkflows\Services\Contracts\WorkflowEvent;
FilamentWorkflows::event([
WorkflowEvent::make('Order shipped')->event(\App\Events\OrderShipped::class),
]);
namespace App\Workflows;
use Filament\Forms\Components\TextInput;
use Illuminate\Support\Facades\Log;
use TomatoPHP\FilamentWorkflows\Events\Models\ModelCreated;
use TomatoPHP\FilamentWorkflows\Models\TriggerHasAction;
use TomatoPHP\FilamentWorkflows\Services\Abstracts\Action;
class WriteToLog extends Action
{
public static function run(mixed $event, TriggerHasAction $action): void
{
$record = $event instanceof ModelCreated ? $event->data : null;
Log::info($action->payload['message'] ?? 'Workflow ran', ['record' => $record?->getKey()]);
}
public static function form(): array
{
return [
TextInput::make('message')->
use TomatoPHP\FilamentWorkflows\Services\Contracts\WorkflowAction;
FilamentWorkflows::action([
WorkflowAction::make('Write to log')->action(\App\Workflows\WriteToLog::class),
]);