Skip to content

Permissions

Now that you have defined you Workflow, Transitions and Permissions, you need to configure your User model to use these permissions as follow:

class User extends Authenticatable implements HasPermissions // <-
{
use FluentPermissions; // <-
// ...
}
  1. Implement HasPermissions interface.
  2. Then you will need to use FluentPermissions traits to define all the needed methods.

You will need after that to configure your User Filament resource to have the form field where you can choose the Workflow permissions for each of your users.

To do it, you will need to use PermissionsField Form field defined by the plugin:

<?php
namespace App\Filament\Resources;
use App\Models\User;
use Devaslanca\Fluent\Forms\Components\PermissionsField;
use Devaslanca\Fluent\Tables\Columns\PermissionsColumn;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
class UserResource extends Resource
{
protected static ?string $model = User::class;
// ...
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\TextInput::make('email')
->email()
->required()
->maxLength(255),
// ...
PermissionsField::init(), // <-
]);
}
// ...
}

This field is based on the Filament CheckboxList field, so feel free to customize it as you like.

The following is how this field renders in the User resource form:

Now your users are ready to use their authorized Workflow Transitions.

To show these permissions in your User resource table, you can use PermissionsColumn as follow:

<?php
namespace App\Filament\Resources;
use App\Filament\Resources\UserResource\Pages;
use App\Filament\Resources\UserResource\RelationManagers;
use App\Models\User;
use Devaslanca\Fluent\Forms\Components\FluentPermissions;
use Devaslanca\Fluent\Forms\Components\PermissionsField;
use Devaslanca\Fluent\Tables\Columns\PermissionsColumn;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
class UserResource extends Resource
{
protected static ?string $model = User::class;
// ...
public static function table(Table $table): Table
{
return $table
->columns([
// ..
PermissionsColumn::init(), // <-
// ...
]);
}
}

This column is based on Filament TextColumn table column and defined as badge() with limitList(1), so feel free to customize it as you like.