Resource
Filament Fluent is a set of Filament components (Resource, Form field, Table columm, …) that provides an intuitive and seamless way to create and manage workflows directly within your Filament project.
The following are the main components of the Filament Fluent plugin that make the magic happen.
Workflow Resource
First of all the Workflow Resource, after you have installed the Filament Fluent plugin a new resource will appear in the menu named Workflows under the navigation group Fluent Transitions.
This resource is essentially a predefined filament resource that will allow you to configure workflows for all your Laravel models.
But before you can use this ressource, you need to configure your models that will interact with Fluent workflows, by adding the following:
<?php
namespace App\Models;
use Devaslanca\Fluent\Interfaces\HasWorkflow;use Devaslanca\Fluent\Traits\FluentWorkflow;use Illuminate\Database\Eloquent\Model;
class Project extends Model implements HasWorkflow // <-{ use FluentWorkflow; // <-
// ...}
- Implements
HasWorkflow
interface. - Then, you will need to use
FluentWorkflow
trait inside your model, to declare the needed methods.
Here is an example of page containing a workflow configuration for a model named Project:
As you can see, the resource contains the following parts:
Main resource form
Will handle the workflow details:
- Title: The workflow title.
- Model: The model that will interact with this workflow, this
Select
field will be populated by all your Laravel models implementing theHasWorkflow
Interface, and using the methodgetWorkflowLabel()
method declared by the traitFluentWorkflow
. - Active: The active flag, that tells that a workflow is activated or not (Need to know: you can create a single active workflow by model, which means if you want to create a new workflow for a model, you need to deactivate the old one).
So feel free to override this method inside your model to change the name of this model.
Resource relations
The Workflow resource manage 2 relations:
- Transitions: The workflow transitions (From State — Action —> To State).
- Permissions: To declare different permissions on these transitions (To handle who can execute a transition on your models).
Transitions
In this section you can manage all the transitions for the selected workflow, as any Filament Resource.
You can also use the View Workflow action, that will open a modal with a visual representation of your workflow:
This diagram representation is using Mermaid.js plugin, more info here: https://mermaid.js.org/
Permissions
In this section you can manage all the permissions for the selected workflow.
These permissions will be used after in your
User
model to declare which user can do your transitions.
The creation/edition permission modal will be like the following:
Policies
If you want to define policies for this Filament resource, you can generate and configure your policy then link your policy with the plugin Model in AppServiceProvider
:
<?php
namespace App\Providers;
use App\Policies\WorkflowPolicy;use Devaslanca\Fluent\Models\Workflow;use Illuminate\Support\Facades\Gate;use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider{ // ...
public function boot(): void { Gate::policy(Workflow::class, WorkflowPolicy::class); }}
You can do the same for
Devaslanca\Fluent\Models\Transition
andDevaslanca\Fluent\Models\Permission
models to handle policies inside the Workflow resource relationships.