Giter VIP home page Giter VIP logo

approvals's Introduction

Approval System

The approval system package is an add-on package that allows seamless integration into laravel 5.7+

Installation

To install simply pull in the package to your laravel project
composer install httpfactory\approvals

After you have successfully installed it via composer, you will need to
register the package in your config\app.php file.

Add the following line to your service providers array :
Httpfactory\Approvals\ApprovalServiceProvider::class

Now you need to run the following command :
php artisan vendor:publish --provider=Httpfactory\Approvals\ApprovalServiceProvider

After registering the package, you will need to run migrations

Run The Migrations

you must run your migrations as follows
php artisan migrate

Events

You will need to add the following events to the app\Providers\EventServiceProvider.php

  • ApprovalRequest

    • Httpfactory\Approvals\Events\ApprovalRequest
    • Fires when someone sends an approval request.
  • ApprovalApproved

    • Httpfactory\Approvals\Events\ApprovalApproved
    • Fires when an "approver" approves the approval request.
  • ApprovalDeclined

    • Httpfactory\Approvals\Events\ApprovalDeclined
    • Fires when an "approver" declines the approval request.
  • ApprovalAwarded

    • Httpfactory\Approvals\Events\ApprovalAwarded
    • Fires when the approval configuration requirements are met and the approval is automatically awarded.
  • ApprovalDenied

    • Httpfactory\Approvals\Events\ApprovalDenied
    • Fires when the approval configuration requirements are met and the approval is automatically denied.

The Events should look something like the code below

           //Begin the approval events
           'Httpfactory\Approvals\Events\ApprovalRequest' => [
               'Httpfactory\Approvals\Listeners\ApprovalRequest',
           ],
   
           'Httpfactory\Approvals\Events\ApprovalApproved' => [
               'Httpfactory\Approvals\Listeners\ApprovalApproved',
           ],
   
           'Httpfactory\Approvals\Events\ApprovalDeclined' => [
               'Httpfactory\Approvals\Listeners\ApprovalDeclined',
           ],
           
           'Httpfactory\Approvals\Events\ApprovalAwarded' => [
               'Httpfactory\Approvals\Listeners\ApprovalAwarded',
           ],
           
           'Httpfactory\Approvals\Events\ApprovalDenied' => [
               'Httpfactory\Approvals\Listeners\ApprovalDenied',
           ],

Usage

There are multiple types of approvals :

  1. Quick Approval ( 1 to 1 )
  2. Group Approval ( a group of users must approve/deny )
  3. MultiTier Approval ( multiple groups must approve/deny )

Quick Approval

Below is an example of a quick approval :

<?php

namespace Acme\SomeProject;

use Httpfactory\Approvals\QuickApproval;
use App\User;

class Someclass {
    
    public function requestApproval(){
        
        //Some user instance that is requesting the approval...
        $user = User::find(1);
        
        //If you have a Laravel Spark and are using "Teams"
        //The User's currentTeam is going to be used as the Team Id association.
               
        //Create a new Approval of certain type, then request the actual approval.
        $approval = new QuickApproval($user);
        $approval->name = 'Credit Card';
        $approval->description = 'Requesting Permission to use the company credit card for something cool';
        $approval->approvalsNeeded = 1;

        $usersThatIneedApprovalFrom = User::where('id', '!=', 1)->get();

        $approval->from($usersThatIneedApprovalFrom)->sendRequest();
    }

}

In the example above, we are sending a request to a user for approval.

approvals's People

Watchers

James Cloos avatar Jaime avatar

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.