Download the PHP package aymanalhattami/laravel-approval without Composer
On this page you can find all versions of the php package aymanalhattami/laravel-approval. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aymanalhattami/laravel-approval
More information about aymanalhattami/laravel-approval
Files in aymanalhattami/laravel-approval
Package laravel-approval
Short Description Attach approvals to any model to prevent unauthorised updates.
License MIT
Informations about the package laravel-approval
Attach modification approvals to any model to prevent unauthorised updates.
Note: This package is forked from cloudcake/laravel-approval in order to support latest laravel version and to add new features
Getting Started
Install the package via composer
Register the service provider
This package makes use of Laravel's auto-discovery. If you are an using earlier version of Laravel (< 5.4) you will need to manually register the service provider.
Add Approval\ApprovalServiceProvider::class
to the providers
array in config/app.php
.
Publish configuration
php artisan vendor:publish --provider="Approval\ApprovalServiceProvider" --tag="config"
Publish migrations
php artisan vendor:publish --provider="Approval\ApprovalServiceProvider" --tag="migrations"
Run migrations
php artisan migrate
Setting Up
Setup Approval Model(s)
Any model you wish to attach to an approval process simply requires the RequiresApproval
trait, for example:
Conditional Approvals
There may be instances where you don't always want your model to go through an approval process, for this reason the the requiresApprovalWhen
is available for your convenience and defaults to false so that no unintended approvals are created behind the scenes:
Optional Attributes
Approval models come with a few optional attributes to make your approval process as flexible as possible. The following attributes are define by default with the set defaults, you may alter them per model as you please.
Setup Approver Model(s)
Any other model (not just a user model) can approve models by simply adding the ApprovesChanges
trait to it, for example:
Any model with the ApprovesChanges
trait inherits the approval access function.
Approver Authorization (Optional)
By default, any model with the ApprovesChanges
trait will be able to approve and disapprove modifications. You can customize your authorization to approve/disapprove modifications however you please by adding the authorizedToApprove
method on the specific approver model:
Disapprover Authorization (Optional)
Similarly to the approval process, the disapproval authorization method for disapproving modifications follows the same logic:
Usage
Retrieving Pending Modifications
Any model that contains the RequiresApproval
trait may have multiple pending modifications, to access these modifications you can call the modifications()
method on the approval model:
Retrieving Only Pending Creations
Retrieving Only Pending Changes
Retrieving Modification Creator
For any pending modifications on a model, you may fetch the model that initiated the modification request:
This (modifier) would usually be a user that changed the model and triggered the approval modification, but because Approval caters for more than just users, it's possible that the creator is any other model.