Code Monkey home page Code Monkey logo

filament-approvals's Introduction

Manage approval processes in your filament application

Latest Version on Packagist Total Downloads

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.

🛠️ Be Part of the Journey

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.

Quick understanding the package

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.

Approval flow

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

Approval step

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.

Installation

You can install the package via composer:

composer require eightynine/filament-approvals

Usage

  1. Run the migrations using:
php artisan migrate
  1. Add the plugin to your panel service provider as follows:
    ->plugins([
        \EightyNine\Approvals\ApprovalPlugin::make()
    ])
  1. Make your model extend the ApprovableModel
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"];
}
  1. Create approval flows
  • 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 😉

  1. Add the approvable actions:
  • In your resource table, add the approvable actions
$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()
            ]
        ),
    )
  • In your view page or edit page, you can include the approval actions using the trait HasApprovalHeaderActions, and define the method getOnCompletionAction() that will return the action(s) to be shown once complete. If this method is not implemented and you use the trait, an error will be thrown.
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())
    }
}
  1. Add the ApprovalStatusColumn to your table to see the status of the approval flow
    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

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

filament-approvals's People

Contributors

eighty9nine avatar tonypartridger avatar jcc5018 avatar enzonotario avatar

Stargazers

Moe Dayraki avatar Alessandro Ribeiro avatar  avatar Rawand J. Rasool avatar Alpha Olomi avatar John Bacon avatar Austin Kregel avatar  avatar Andhika Yuana avatar Jcoder avatar Mohamed Habib Khattat avatar Septiawan Aji Pradana avatar Chiao F avatar Andriel Ferreira avatar Chris Jones avatar Kolja avatar Yudi Purwanto avatar Wiranda Boy Prakasa avatar John Trickett avatar  avatar  avatar Bruno Torrinha avatar Hussain Aminu avatar Hadi Swais avatar Vittorio Dormi Delgado avatar LiveSource avatar TwoPinkyNoBrain avatar  avatar Julio Cavallari avatar Jose Rosado avatar Tony Partridge avatar Connor Howell avatar Emrah ÖZDEMİR avatar Stephen Jude avatar George avatar Elijah Ervin avatar Marco Germani avatar  avatar  avatar kevin florenz daus avatar gaobin lee avatar Blaze avatar Sephyi avatar Mio noel dAvis avatar Louise Yousre avatar Tristan Bendixen avatar Konstantin Mazurov avatar ziming avatar Joseph Macharia avatar Habib Talib avatar Josie Darang avatar Zainal Hasan avatar Muhammed Cetin avatar HAMAD ABDULLA avatar Jèfferson Gonçalves avatar Alade YESSOUFOU avatar AriaieBOY avatar MEHDI avatar Saif Allah Khaled avatar  avatar php coder avatar

Watchers

Tony Partridge avatar  avatar

filament-approvals's Issues

Syntax error: syntax error at or near "order" - PostgreSQL & Backticks

image

Using PostgreSQL i'm getting an error when sorting SQL query by the order column because of the backticks that are used in the query.

PostgreSQL against MySQL uses double quotes for quoting identifiers, so PostgreSQL does not recognize it.

Syntax error           Query response

ORDER BY 
  `ORDER` ASC,   ==>   "ORDER" ASC, 
  id ASC

What do you think would be the best solution for this problem?

Error for view action

In my ViewLeaveRequest I added the getOnCompletionAction() function as described in the usage section.
When I click on a row or on the View button I get the error "Call to undefined method App\Models\LeaveRequest::shouldBeHidden()".
This happens on non aproved leave request and fully approved ones.
Any idea what went wrong? I imported ApprovableModel with use EightyNine\Approvals\Models\ApprovableModel;
Kr. Albert Oxener

How to hide Approval Flows menu?

Hi,

We can hide the menu by set to false on config/approvals.php file:
"should_register_navigation" => true,

But it will hide from all users.
Even I have configured it using Shield, the menu still appears. It seems the menu can't be accessed/controlled by Shield.

How the proper way to hide the Approval Flows menu by user's role?

Thanks,

"VERIFY" is not a valid backing value for enum "RingleSoft\LaravelProcessApproval\Enums\ApprovalTypeEnum"

Hi,
As subject, I have that error message when my flow contains "VERIFY" action step.
The record will create successfully but the Approval status column value is "No Status Exists" and status is "Done", no Approval actions list (Approve or Reject).

Following is the laravel.log for that error:

[2024-07-22 10:16:26] local.ERROR: "VERIFY" is not a valid backing value for enum "RingleSoft\LaravelProcessApproval\Enums\ApprovalTypeEnum" {"userId":1,"exception":
"[object] (ValueError(code: 0): \"VERIFY\" is not a valid backing value for enum \"RingleSoft\\LaravelProcessApproval\\Enums\\ApprovalTypeEnum\" at /home/alfresco/do
cflow.bw.intranet/vendor/ringlesoft/laravel-process-approval/src/DataObjects/ApprovalStatusStepData.php:96)
[stacktrace]

I use Filament v3.2.95, Laravel v10.48.16 and PHP 8.1.2.

Thanks,
[bayu]

The plugin works a bit differently I need...

Thank you for your plugin!

I added "ringlesoft/laravel-process-approval": "^1.0" and "eightynine/filament-approvals": "^3.1"
into Laravel 10.48.14/"filament/filament": "^3.2-stable" app, but it works a bit differently I need :

  1. I added into Doc model

extends ApprovableModel
so when new model is added it has 1 rows in process_approval_statuses table with

status = Created

  1. in Docs Resources I added :
            ->actions([
                ...\EightyNine\Approvals\Tables\Actions\ApprovalActions::make(
                    Action::make("Approve 987"), // "987" - JUST TO SEE THAT IS MY OPTION
                    [
                        Tables\Actions\EditAction::make(), // I REALLY DO NOT UNDERSTAND
                        Tables\Actions\ViewAction::make()  //  WHAT FOR THESE 2 LINES
                    ]
                ),
            ])

```But in listing I see 2 buttons :

    https://img001.prntscr.com/file/img001/j4XEME18SkWa1Kle4-k38g.png

but I need only 1 action "Approve", not "Submit"

3) When I select "Submit" option in 1st "Approvals" button I see
that status in process_approval_statuses = "Submitted" - I need "Approved"


4) If to hide

`    ->actions([`

lines - I do not have 2 buttons I show in printscreen

5) I added line :

`    \EightyNine\Approvals\Tables\Columns\ApprovalStatusColumn::make("approvalStatus.status"),
`
in table method I have error :

`    Attempt to read property "name" on null`

Maybe because Doc model have no "name" field ? Is it configurable ?

Real life example required.

I have gone through the documentation a couple of times and didn't grasp the flow of approvals in its entirety. May I ask the author or someone else with implementation knowledge to post a real-world implementation example.

What I want to achieve:

A location recorded is created
Approval is auto started as per the approval step defined
All approvers approve the approval
Finally, the status of location is set to active, a custom notification is sent to the initiator.

Current Setup:
Filament v3, filament-approvals correctly setup:

i got Attempt to read property "status" on null

Attempt to read property "status" on null

Models

namespace App\Models;

use EightyNine\Approvals\Models\ApprovableModel;

class Sig extends ApprovableModel
{
    protected $guarded = [];

    // get staff name
    public function user()
    {
        return $this->belongsTo(User::class, 'user_to_sig');
    }
}

resource

return $table
            ->columns([
                Tables\Columns\TextColumn::make('name'),
                \EightyNine\Approvals\Tables\Columns\ApprovalStatusColumn::make("approvalStatus.status"),
            ])
            ->filters([
                //
            ])
            ->actions([
                Tables\Actions\EditAction::make(),
                ...\EightyNine\Approvals\Tables\Actions\ApprovalActions::make(
                    Action::make("Done")
                ),
            ])

image

image

image

Old data

How can I approve model instances already saved before the package installation and their workflow created ?
Because in my case, when I try to make the validation nothing happens.

Help me please.

Error Call to undefined method App\Models\User::getFilamentName()

Installed the plugin and did a change with a user, then let the assigned role for approval check the record. When I click on the row under Approval status, it will give an error "Call to undefined method App\Models\User::getFilamentName()". When commenting out the line in vendor/eightynine/filament-approvals/resources/views/tables/columns/approval-status-column-action-view.blade.php, error is gone.

I found that the getFilamentName might be something coming with a multi tenancy setup, as I found it in the docs here: https://docs.laravel-filament.cn/docs/panels/tenancy/. Now I'm not having this setup for my filament install. Does it mean you need to have a multi tenancy setup ideally?

Undefined property: Illuminate\Database\Eloquent\Relations\BelongsTo::$name

The error message is showing when the user created new Purchase Request.
Undefined property: Illuminate\Database\Eloquent\Relations\BelongsTo::$name

when i remove this line \EightyNine\Approvals\Tables\Columns\ApprovalStatusColumn::make("approvalStatus.status"), from the table column the error gone. Then the user will submit the approval to verify. When i uncomment this \EightyNine\Approvals\Tables\Columns\ApprovalStatusColumn::make("approvalStatus.status"), it works as it should.

This happens everytime the user created new PR

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.