exceptio/laravel-approval

Dynamic Approval Package For Laravel Framework

v1.0.8 2024-05-16 06:47 UTC

This package is auto-updated.

Last update: 2024-05-16 06:53:39 UTC


README

A Dynamic package for handling model based approval process in Laravel.

Installation

This package is very easy to set up. There are only couple of steps.

Composer

Pull this package in through Composer

composer require exceptio/laravel-approval

Service Provider

  • Laravel 5.5 and up Uses package auto discovery feature, no need to edit the config/app.php file.

  • Laravel 5.4 and below Add the package to your application service providers in config/app.php file.

'providers' => [

    ...

    /**
     * Third Party Service Providers...
     */
    Exceptio\ApprovalPermission\ApprovalPermissionServiceProvider::class,

],

Config File

Publish the package config file to your application. Run these commands inside your terminal.

php artisan vendor:publish --provider="Exceptio\ApprovalPermission\ApprovalPermissionServiceProvider" --tag="config"

you may set approvalpermission-enable to false to disable the feature. you may set do-migration to false in config file to disable the migration. Note: database must have all the necessary tables and columns if you disable migration.

View Files

Publish the view file to your application. Run these commands inside your terminal.

php artisan vendor:publish --provider="Exceptio\ApprovalPermission\ApprovalPermissionServiceProvider" --tag="views"

Migration File

Publish the package migration file to your application. Run these commands inside your terminal.

php artisan vendor:publish --provider="Exceptio\ApprovalPermission\ApprovalPermissionServiceProvider" --tag="migration"

Notificaiton File

Publish the package notificaiton file to your application. Run these commands inside your terminal.

php artisan vendor:publish --provider="Exceptio\ApprovalPermission\ApprovalPermissionServiceProvider" --tag="notificaiton"

Approvable Trait

  1. Include Approvable trait to a class for approval process. See example below.

Example Approvable Trait:

<?php

namespace App\Repositories;

use App\Models\User;
use App\Models\Member;

use Exceptio\ApprovalPermission\Approvable;

class MemberRepository
{
    use Approvable;

    const DRAFT_DATA = 0;   // Draft member
    const PENDING_DATA = 1;   // Pending member

    // rest of your code ...
}

Migrations and seeds

This uses the default users table which is in Laravel. You should already have the migration file for the users table available and migrated.

  1. Setup the needed tables:
php artisan migrate
  1. For seeder publish
php artisan vendor:publish --provider="Exceptio\ApprovalPermission\ApprovalPermissionServiceProvider" --tag="seeder"
  1. Seed an initial set of Approval sample data.
composer dump-autoload
php artisan db:seed --class="ApprovalSeeder"

And that's it!

Usage

Creating Process

<?php
use App\Models\User;
use App\Models\Member;

use Exceptio\ApprovalPermission\Approvable;
class MemberRepository
{
    use Approvable;

    const DRAFT_DATA = 0;   // Draft member
    const PENDING_DATA = 1;   // Pending member
    
    public function createStepFinal(Request $request)
    {
      $member = new Member::create([
        'name' => 'Test Member',
        //so on
      ]);
      $this->notifyApprovalCreate($member);
    }

Blade Extensions

The Blade extensions.

@approvalMenu() //Show Approval menu in your application

Config File

You can change user model name, primary key and other settings in config. Have a look at config file for more information.

Opening an Issue

Before opening an issue there are a couple of considerations:

  • A star on this project shows support and is way to say thank you to all the contributors. If you open an issue without a star, your issue may be closed without consideration. Thank you for understanding and the support.
  • Read the instructions and make sure all steps were followed correctly.
  • Check that the issue is not specific to your development environment setup.
  • Provide duplication steps.
  • Attempt to look into the issue, and if you have a solution, make a pull request.
  • Show that you have made an attempt to look into the issue.
  • Check to see if the issue you are reporting is a duplicate of a previous reported issue.
  • Following these instructions show me that you have tried.
  • If you have a questions send me an email to zahid@exceptionsolutions.com
  • Please be considerate that this is an open source project that I provide to the community for FREE when opening an issue.

License

Dynamic Approval Permission For Laravel Project by Exception Solutions is marked with CC0 1.0 Universal 68747470733a2f2f6d6972726f72732e6372656174697665636f6d6d6f6e732e6f72672f70726573736b69742f69636f6e732f63632e7376673f7265663d63686f6f7365722d763168747470733a2f2f6d6972726f72732e6372656174697665636f6d6d6f6e732e6f72672f70726573736b69742f69636f6e732f7a65726f2e7376673f7265663d63686f6f7365722d7631