Download the PHP package cjmellor/approval without Composer

On this page you can find all versions of the php package cjmellor/approval. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package approval

Latest Version on Packagist GitHub Tests Action Status Total Downloads Packagist PHP Version Laravel Version

Approval is a Laravel package that provides a simple way to approve new Model data before it is persisted.

Installation

You can install the package via composer:

You can publish and run the migrations with:

You can publish the config file with:

This is the contents of the published config file:

The config allows you to change the polymorphic pivot name. It should end with able though.

Usage

[!NOTE] The package utilises Enums, so both PHP >= 8.1 and Laravel 10 must be used.

Note This package does not approve/deny the data for you, it just stores the new/amended data into the database. It is up to you to decide how you implement a function to approve or deny the Model.

Add the MustBeApproved trait to your Model and now the data will be stored in an approvals table, ready for you to approve or deny.

For example, you add it to a Post Model and each time a Post is created or updated, all the dirty data will be stored in the database as JSON for you to do something with it.

All Models using the Trait will now be stored in a new table -- approvals. This is a polymorphic relationship.

Here is some info about the columns in the approvals table:

approvalable_type => The class name of the Model that the approval is for

approvalable_id => The ID of the Model that the approval is for

state => The state of the approval. This uses an Enum class. This column is cast to an ApprovalStatus Enum class

new_data => All the fields created or updated in the Model. This is a JSON column. This column is cast to the AsArrayObject Cast

original_data => All the fields in the Model before they were updated. This is a JSON column. This column is cast to the AsArrayObject Cast

rolled_back_at => A timestamp of when this was last rolled back to its original state

audited_at => The ID of the User who set the state

foreign_key => A foreign key to the Model that the approval is for

Bypassing Approval Check

If you want to check if the Model data will be bypassed, use the isApprovalBypassed method.

Foreign Keys for New Models

[!NOTE] It is recommended to read the below section on how foreign keys work in this package.

[!IMPORTANT] By default, the foreign key will always be user_id because this is the most common foreign key used in Laravel.

If you create a new Model directly via the Model, e.g.

be sure to also add the foreign key to the Model, e.g.

Now when the Model is sent for approval, the foreign key will be stored in the foreign_key column.

Customise the Foreign Key

Your Model might not use the user_id as the foreign key, so you can customise it by adding this method to your Model:

Scopes

The package comes with some helper methods for the Builder, utilising a custom scope - ApprovalStateScope

By default, all queries to the approvals table will return all the Models' no matter the state.

There are three methods to help you retrieve the state of the Approval.

You can also set a state for an approval:

In the event you need to reset a state, you can use the withAnyState helper.

Helpers

Conditional helper methods are used, so you can set the state of an Approval when a condition is met.

Events

Once a Model's state has been changed, an event will be fired.

Persisting data

By default, once you approve a Model, it will be inserted into the database.

If you don't want to persist to the database on approval, set a false flag on the approve method.

Rollbacks

If you need to roll back an approval, you can use the rollback method.

[!NOTE] By default, a Rollback will bypass been added back to the approvals table

This will revert the data and set the state to pending and touch the rolled_back_at timestamp, so you have a record of when it was rolled back.

If you want a Rollback to be re-approved, pass the bypass parameter as false to the rollback method

Conditional Rollbacks

A roll-back can be conditional, so you can roll back an approval if a condition is met.

Events

When a Model has been rolled back, a ModelRolledBack event will be fired with the Approval Model that was rolled back, as well as the User that rolled it back.

`

Disable Approvals

If you don't want Model data to be approved, you can bypass it with the withoutApproval method.

Specify Approvable Attributes

By default, all attributes of the model will go through the approval process, however if you only wish certain attributes to go through this process, you can specify them using the approvalAttributes property in your model.

In this example, only the name attribute of this model will go through the approval process, all mutations on other attributes will bypass the approval process.

If you omit the approvalAttributes property from your model, all attributes will go through the approval process.

Testing

Changelog

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

Contributing

Please open a PR with as much detail as possible about what you're trying to achieve.

Credits

License

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


All versions of approval with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/contracts Version ^10.0|^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package cjmellor/approval contains the following files

Loading the files please wait ....