百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
L

laravel-process-approval

> 后端框架
开源

Laravel Process Approval 是一个 Laravel 包,可让您轻松地为 Laravel 应用添加审批功能。它允许您定义审批工作流程,并为每个工作流程定义审批人员。

553 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

Laravel Process Approval 是一个 Laravel 包,可让您轻松地为 Laravel 应用添加审批功能。它允许您定义审批工作流程,并为每个工作流程定义审批人员。

Laravel Process Approval


Introduction

This package enables multi-level approval workflows for Eloquent models in your Laravel application. If you have models that require review and approval from multiple approvers before execution, this package provides a flexible approval process to meet that need.

Laravel 10.0 or later

The package relies on an existing Role management. This can be a custom role management or another package such as Spatie's laravel permissions.

Installation

1. Install Using composer:

bash
composer require ringlesoft/laravel-process-approval

2. Publish Files (Optional)

This package provides publishable files that include configuration, migrations and views. You can publish these files using the following command:

bash
php artisan vendor:publish --provider="RingleSoft\LaravelProcessApproval\LaravelProcessApprovalServiceProvider" 

You can publish specific files by providing the --tag option within the publish command. Available options are approvals-migrations, approvals-migrations-uuids, approvals-config, approvals-views, approvals-translations. For example:

bash
php artisan vendor:publish --provider="RingleSoft\LaravelProcessApproval\LaravelProcessApprovalServiceProvider" --tag="approvals-migrations" 

Note: If you run php artisan process-approval:install, it will publish the selected migration set for you (bigint by default, UUIDs with --uuids).

UUID Support (Optional)

This package supports UUID primary keys for all package tables and UUID-based polymorphic relations.

If you want to use UUIDs, it is recommended to use the install command (this publishes the correct migrations and updates the published config):

bash
php artisan process-approval:install --uuids

If you need to overwrite already published files, you can pass --force:

bash
php artisan process-approval:install --uuids --force

If you prefer to publish migrations manually, a UUID migration tag is also available:

bash
php artisan vendor:publish --provider="RingleSoft\LaravelProcessApproval\LaravelProcessApprovalServiceProvider" --tag="approvals-migrations-uuids"

Note: If you manually publish migrations, make sure you set load_migrations in the config file to false to avoid running migrations twice. Running process-approval:install will set this variable to false for you.

3. Run migration:

The package comes with four migration files. Run artisan migrate command before you start using the package.

bash
php artisan migrate

4. Create Approval flows and Steps

The package relies on Approval flows and steps on your default database. This is to enable multiple approval flows within the system. You can implement your own way of creating and managing the flows. However, there are available command-line functions to help you get started easily.

i. Creating a new flow

To create a new flow, Run the following command on your terminal.

bash
 php artisan process-approval:flow add FundRequest

ii. Creating a step for the flow

bash
php artisan process-approval:step add  

This will show a list of available Flows. Select the flow yow want to add steps to and then select the role and approval action.

iii. Deleting a flow

bash
php artisan process-approval:flow remove  

This will show a list of available flows. Select the step you want to delete and hit enter.

iv. Deleting a step

bash
php artisan process-approval:step remove  

This will show a list of available steps. Select the step you want to delete and hit enter.

v. Listing all flows

bash
php artisan process-approval:flow list  

This will show a list of all available flows and steps

Usage

1. Implement ApprovableModel on your approvable model

php
class FundRequest extends Model implements ApprovableModel
{

   // Your model content

}

2. Apply the Approvable trait to the model

php
class FundRequest extends Model implements ApprovableModel
{
    use \RingleSoft\LaravelProcessApproval\Traits\Approvable;
   // Your model content

}

3. Implement the onApprovalCompleted() method.

This package relies on one callback method in your model to commit the last approval and mark the approval process as completed. You should implement this method and return true to finalize the approval or false to roll back the last approval. This is useful in the case of performing specific tasks when the approval procedure is completed.

php
class FundRequest extends Model implements ApprovableModel
{
    use \RingleSoft\LaravelProcessApproval\Traits\Approvable;
   // Your model content
   
    public function onApprovalCompleted(ProcessApproval $approval): bool
    {
        // Write logic to be executed when the approval process is completed
        return true;
    }
}

4. Place the `` component on the show page of your model and provide the model instance using the model parameter.

php
    

Currently, the UI is implemented using tailwind, bootstrap or vanilla css. You can switch between the frameworks by modifying the css_library setting in the configuration file. Additionally, you have the option to publish the views and customize them to meet your specific requirements.

Configuration

You can publish the configuration file of this package, process_approval.php, and modify the variables to align with your specific requirements. If you wish to publish the files, use the following command:

bash
php artisan vendor:publish --provider="RingleSoft\LaravelProcessApproval\LaravelProcessApprovalServiceProvider" --tag="approvals-config"

Configurable parameters

  • roles_model - Specify the full class name of the model related to roles table. (default is Spatie's laravel-permissions (Spatie\Permissions\Models\Role))
  • users_model - Specify the model that represents the authenticated users. (default is App\Models\User).
  • models_path - Specify the default namespace for models in your application. (default is App\Models).
  • approval_controller_middlewares - Specify any middlewares you want to apply to the ApprovalController. (Normally it should be ['auth']).
  • css_library - Specify the css library for styling the UI component (bootstrap/tailwind). (default is Tailwind CSS).
  • multi_tenancy_field - Specify the multi-tenancy field in the users table. (default is tenant_id)
  • use_uuids - Enable UUID support for all package tables and UUID-based polymorphic relations (recommended for fresh installs).
  • load_migrations - If true, the package auto-loads vendor migrations. If you publish migrations into your app, make sure set this to false.

Model Submitting

By default, the model becomes ready for approval when it is marked as "submitted". This provides the opportunity for editing and other actions on the model before the approval procedure commences. This feature is particularly useful if you wish to keep newly created models hidden from approvers until the creator submits them.

If you want the model to be auto-submitted upon creation, you can add the following property to the model:

php
public bool $autoSubmit = true;

Or define the method enableAutoSubmit(): bool in your model (Recommended).

php
public function enableAutoSubmit(): bool
{
    // Your logic here
    return true;
}

Otherwise, the package will show a submit button on the show page of the model to enable the creator to submit the model.

Bypassing Approval Process

If you want to bypass the approval process for a particular model instance, you can define the method bypassApprovalProcess(): bool in your model and return true.

php
public function bypassApprovalProcess(): bool
{
    // Your logic here
    return true;
}

Pausing Approval process

Sometimes you may wish to interrupt the approval procedure by adding your own actions before continuing with approvals. You can pause approvals by adding a pauseApprovals(): mixed method to your Approvable Model.

php
public function pauseApprovals() {
    // Your logic here
    return true;
}

If this method returns true, the approval actions UI will disappear, and you will be able to implement your other logics. If the method returns 'ONLY_ACTIONS' the existing approvals will be displayed but approval actions will be hidden and disabled.

Approval Signatures

If you want to use signatures for users, add the getSignature() method to your User model and make it return the signature of the user as image url.

php
Class User extends Model {
    ...
    
    public function getSignature(){
        return $this->signature_path; // Return the path to user's signature
    }
}

If not specified, the package will display check icon for approval and times icon for rejection.

Approval Summary

If you want to display a summary of the approval process (normally when listing the models) you can use the `` component. This component returns html code with icons representing every approval step: check icon representing Approved, times icon representing Rejected or Discarded and exclamation icon representing Pending.

Events

The package dispatches events during different stages of the approval workflow to allow hooking into the process.

  • ProcessSubmittedEvent - Dispatched when a new approvable model is submitted.
  • ProcessApprovedEvent - Dispatched when an approvable model is approved by an approver.
  • ProcessRejectedEvent - Dispatched when an approvable model is rejected by an approver.
  • ProcessReturnedEvent - Dispatched when an approvable model is returned back to the previous step by an approver.
  • ProcessDiscardedEvent - Dispatched when an approvable model is discarded by an approver.
  • ProcessApprovalCompletedEvent - Dispatched when the full approval workflow is completed (approved or discarded).
  • ApprovalNotificationEvent - Dispatched during approval actions with a notification message about what happened.

Showing Notifications

To display approval notifications, subscribe to the ApprovalNotificationEvent event.

1. Create a Listener:

Generate a listener for the event using artisan command:

bash
php artisan make:listener ApprovalNotificationListener --event=\\RingleSoft\\LaravelProcessApproval\\Events\\ApprovalNotificationEvent

2. Implement Listener Logic:

Inside the generated ApprovalNotificationListener class, implement the logic within the handle() method. This method will execute whenever the ApprovalNotificationEvent event is triggered. Customize the notification content and delivery method as per your application's requirements.

Example listener implementation:

php
class ApprovalNotificationListener
{
    ...
    /**
     * Handle the event.
     */
    public function handle(ApprovalNotificationEvent $event): void
    {
        session()->flash('success', $event->message);
    }
}

3. Register Listener:

Register the listener in your EventServiceProvider class to link the ApprovalNotificationEvent event with your ApprovalNotificationListener:

php
protected $listen = [
    ApprovalNotificationEvent::class => [
        ApprovalNotificationListener::class,
    ],
];

Use your own approach to display notification from session()

Notifying Approvers

To notify approvers when a document is awaiting their approval, you can subscribe to the ProcessSubmittedEvent and ProcessApprovedEvent events and send notifications to them.

Here is an example of how to send notifications to the next approvers within the ProcessSubmittedListener listener:

php
    public function handle(ProcessSubmittedEvent $event): void
    {
        $nextApprovers = $event->approvable->getNextApprovers();
        foreach ($nextApprovers as $nextApprover) {
            $nextAp

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPapproval-processapprovalsbladelaravel

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架