This package allows you to implement approval flows in your Laravel Filament application.
This package brings the ringlesoft/laravel-process-approval) functionalities to filament. You can use all the ringlesoft/laravel-process-approval features in your laravel project. It also uses the spatie/laravel-permissions package, so you can use all its features.
Hi, I'm Eighty Nine. I created aprovals plugin to solve real problems I faced as a developer. Your sponsorship will allow me to dedicate more time to enhancing these tools and helping more people. Become a sponsor and join me in making a positive impact on the developer community.
Some processes in your application require to be approved by multiple people before the process can be completed. For example, an employee submits a timesheet, then the supervisor approves, then manager approves and finally the HR approves and the timesheet is logged. This package is a solution for this type of processes.
This is the chain of events for a particular process. For example, timesheet submission, expense request, leave request. These processes require that multiple people have check and approve or reject, until the process is complete.
Approval flows are based on a model, example, ExpenseRequest, LeaveRequest, TimesheetLogSubmission etc
These are the steps that the process has. Each step is associated with a role that contains users that need to approve. When any of the users in the role approves, the process moves forward to the next step.
This package is based on roles, which are provided by the package spatie/laravel-permission.
You can install the package via composer:
composer require eightynine/filament-approvals
php artisan migrate
->plugins([ \EightyNine\Approvals\ApprovalPlugin::make()])
namespace App\Models; use EightyNine\Approvals\Models\ApprovableModel;use Illuminate\Database\Eloquent\Factories\HasFactory;use Illuminate\Database\Eloquent\Model; class LeaveRequest extends ApprovableModel{ use HasFactory; protected $fillable = ["name"];}
In your dashboard, a "Approval flows menu will have appeared". Click it and start creating the approval flows. The name is the name of the model, that you are using in your flow.
After you create your first approval create the steps. The steps will require that you have already create roles in your admin panel using the spatie/laravel-permission package.
You can move to the next step 😉
$table ->actions( ...\EightyNine\Approvals\Tables\Actions\ApprovalActions::make( // define your action here that will appear once approval is completed Action::make("Done"), [ Tables\Actions\EditAction::make(), Tables\Actions\ViewAction::make() ] ), )
namespace App\Filament\Resources\LeaveRequestResource\Pages; use App\Filament\Resources\LeaveRequestResource;use Filament\Actions;use Filament\Actions\Action;use Filament\Resources\Pages\ViewRecord; class ViewLeaveRequest extends ViewRecord{ use \EightyNine\Approvals\Traits\HasApprovalHeaderActions; protected static string $resource = LeaveRequestResource::class; /** * Get the completion action. * * @return Filament\Actions\Action * @throws Exception */ protected function getOnCompletionAction(): Action { return Action::make("Done") ->color("success") // Do not use the visible method, since it is being used internally to show this action if the approval flow has been completed. // Using the hidden method add your condition to prevent the action from being performed more than once ->hidden(fn(ApprovableModel $record)=> $record->shouldBeHidden()) }}
return $table ->columns([ TextColumn::make("name"), \EightyNine\Approvals\Tables\Columns\ApprovalStatusColumn::make("approvalStatus.status"), ])...
Just like that, you are good to go, make some moneyyyyy🤑
To add more approval flows(models), repeat the steps 3-6
This package provides extensive customization options by publishing various components. You can publish and customize configuration files, views, Filament resources, form/table components, translations, and more.
Use the custom publish command for an interactive publishing experience:
php artisan approvals:publish
This will show you an interactive menu to choose what you want to publish.
You can also publish specific components using command options:
php artisan approvals:publish --config
This publishes the configuration file to config/approvals.php
where you can customize:
php artisan approvals:publish --views
This publishes all Blade view files to resources/views/vendor/filament-approvals/
for complete UI customization:
tables/columns/approval-status-column.blade.php
- Customize the approval status displaytables/columns/approval-status-column-action-view.blade.php
- Customize approval history viewphp artisan approvals:publish --resources
This publishes Filament resources to app/Filament/Resources/
allowing you to:
php artisan approvals:publish --components
This publishes reusable components to app/Forms/Approvals/
and app/Tables/Approvals/
:
php artisan approvals:publish --translations
This publishes language files to resources/lang/vendor/filament-approvals/
for localization:
php artisan approvals:publish --stubs
This publishes stub files to stubs/filament-approvals/
for development and extension.
php artisan approvals:publish --all
This publishes all customizable files at once.
After publishing the config file, you can customize these settings in config/approvals.php
:
return [ // Specify your role model (must be compatible with spatie/laravel-permission) "role_model" => App\Models\Role::class, // Navigation configuration "navigation" => [ "should_register_navigation" => true, "icon" => "heroicon-o-clipboard-document-check", "sort" => 1 ], // Comment settings "enable_approval_comments" => false, // Allow comments when approving "enable_rejection_comments" => true, // Allow comments when rejecting];
After publishing views, you can completely customize the appearance:
Approval Status Column (resources/views/vendor/filament-approvals/tables/columns/approval-status-column.blade.php
):
Approval History View (resources/views/vendor/filament-approvals/tables/columns/approval-status-column-action-view.blade.php
):
When you publish the Filament resources, you gain full control:
// In your published ApprovalFlowResourceclass ApprovalFlowResource extends Resource{ // Add custom form fields public static function form(Form $form): Form { return $form->schema([ // ... existing fields ... // Add your custom fields TextInput::make('custom_field') ->label('Custom Configuration'), ]); } // Customize table columns public static function table(Table $table): Table { return $table->columns([ // ... existing columns ... // Add custom columns TextColumn::make('custom_data') ->label('Custom Information'), ]); }}
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.
Eighty Nine is a software developer who loves to create plugins and packages for the Laravel ecosystem. He is passionate about sharing his knowledge and experience with other developers through medium and social media. He believes in pouring all the love and effort in his work.