Download the PHP package prismaticoder/maker-checker-laravel without Composer
On this page you can find all versions of the php package prismaticoder/maker-checker-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download prismaticoder/maker-checker-laravel
More information about prismaticoder/maker-checker-laravel
Files in prismaticoder/maker-checker-laravel
Package maker-checker-laravel
Short Description A package for simplifying the integration of a maker-checker approval process to your Laravel application.
License MIT
Informations about the package maker-checker-laravel
prismaticoder/maker-checker-laravel
The prismaticoder/maker-checker-laravel
package is a comprehensive Laravel package that provides a flexible and customizable maker-checker system for your application. It allows you to implement an approval workflow for various actions in your application, such as creating, updating, and deleting records. It also allows you to be able to execute random actions. With this package, you can ensure that important actions go through an approval process before they are finalized.
Features
- Maker-Checker System: Implement an approval workflow for critical actions in your application, ensuring that changes are reviewed and approved before being finalized.
- Flexible Configuration: Customize the maker-checker settings to fit your application's specific needs. Define models that are allowed to make/check requests, minutes till requests are deemed as expired etc.
- Event Driven: The package triggers events throughout the approval workflow, allowing you to hook into these events and perform custom actions or integrations.
- Logging and Auditing: Track and log the approval process, including who made the request, who approved it, and when. Gain insights into the history of actions and approvals.
Requirements
- PHP 8 or higher
- Laravel 8 or higher
The Maker-Checker Laravel package requires PHP version 8 or higher and Laravel version 8 or higher to function properly. Before installing the package, make sure your development environment meets these requirements.
You can check your PHP version by running the following command in your terminal:
Installation
You can install the prismaticoder/maker-checker-laravel
package via Composer. Run the following command in your terminal:
Configuration
After installing the package, you need to publish the configuration and migration files to customize the maker-checker settings. Run the following command:
Migration:
Config:
This will create a config/makerchecker.php
file in your application's config as well as a create_maker_checker_requests_table
migration file in your database/migrations
folder
Usage
Retrieving requests
The package exposes a MakerCheckerRequest
model that can be queried like any other Laravel model
Initiating a new request
One of the ways of initiating a new request is by making use of the MakerChecker
Facade class. Here's an example of how to initiate a request to create a user:
Alternatively, you can choose to include the MakesRequests
trait in your maker model.
With this included, the above requests can now be constructed in the format below
You can also give the request a custom description with the description()
method.
The Executable Request Type
Asides the generic actions of creating, updating and deleting models, it is also possible that you would want to perform miscellaneous requests that do not directly fall into any of this categories e.g making an http call to an external system, combining different actions etc. It is for this reason that the concept of an executable request was added.
To initiate a new executable request, you first need to create an executable request class that extends the Primaticode\MakerChecker\Contracts\ExecutableRequest
contract:
Here, we have an executable request that does something basic when approved: it facilitates a payment based on parameters within the request payload.
To initiate a request to perform this, we use the requestToExecute()
method:
When this request is approved, a call will be made to the execute()
method of the executable class to facilitate the action specified.
Customizing the Request with tap()
The request builder provides a tap()
method that allows you to customize the underlying request object by applying actions or modifications. The tap()
method accepts a closure function as its argument, where you can perform various operations on the request.
Here's an example:
In the above example, the tap()
method is used to customize the request by setting the value of a custom field in the table storing the requests.
Note that the tap()
method is optional and can be used whenever you need to perform additional actions or modifications on the request before it is initiated.
By leveraging the tap() method, you have the flexibility to customize the request object according to your specific requirements, ensuring that it captures all the necessary details for the maker-checker process.
Approving/Rejecting a Request
To approve or reject a Maker-Checker request, you can use the MakerChecker facade as well. Here's an example of how to approve a request:
In the example above, we use the approve()
method of the MakerChecker
facade to approve a request. We pass an instance of the request model and the user who is approving the request.
Similarly, you can use the reject()
method to reject a request:
Just like the MakesRequests
trait, this package also provides a ChecksRequests
traits that can be included in the checking model:
With the above done, approval and rejection can now look like this:
Event Listeners and User-Defined Callbacks
The Maker-Checker package fires events at different stages of the request lifecycle, allowing you to listen to these events and perform additional actions as needed. In addition to event listeners, you can also pass in user-defined callbacks when initiating a request to specify actions to be performed after/before the request is approved or rejected.
Listening to Events
You can listen to the Maker-Checker events by registering event listeners in your application. Here's an example of how to listen to the events provided by the package
In the example above, we use the Event::listen()
method to register a listener for the four events exposed by the package. The event listener receives an instance of the event and can then proceed to take actions on the request as passed in the event.
User-Defined Callbacks
When initiating a Maker-Checker request, you can also pass in user-defined callbacks to specify actions to be performed after/before the request is approved or rejected. Here's an example of how to use user-defined callbacks:
These five different methods can be chained to determine actions to happen during different events in the request lifecycle.
That's it! You're now equipped with event listeners and user-defined callbacks to extend the functionality of the Maker-Checker package in your Laravel application.
Credits
This package draws some inspiration from the excellent spatie/laravel-activitylog
package by Spatie. I'm thankful for their constant work in developing the Laravel ecosystem.
Contributing
I'm happy to receive contributions from the community to enhance and improve this package. Feel free to submit bug reports, feature requests, or pull requests here.
License
The prismaticoder/maker-checker-laravel
package is open-source software licensed under the MIT license. Please refer to the LICENSE file for more information.
All versions of maker-checker-laravel with dependencies
illuminate/config Version ^8.0 || ^9.0 || ^10.0
illuminate/database Version ^8.0|^9.0|^10.0
illuminate/support Version ^8.0|^9.0|^10.0
laravel/serializable-closure Version ^1.2.2