Download the PHP package msnisha/laraflow without Composer
On this page you can find all versions of the php package msnisha/laraflow. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download msnisha/laraflow
More information about msnisha/laraflow
Files in msnisha/laraflow
Package laraflow
Short Description Laravel workflow package for Eloquent models.
License MIT
Informations about the package laraflow
Forked to change the Laravel Version Supported hoping to bring more features to this
Laraflow Workflow Package
Laraflow is a standard workflow package for Laravel Eloquent objects. You can define your steps, the transition between the them, callbacks, and validators.
Installation (via composer)
You can install the package via composer. The package require Laravel 5.5 or higher
You need to crate the necessary table for the historical data:
After Laravel 5.5 you don't need to manually add the service provider to the config/app.php.
Configuration array
You need a configuration array before you use the Laraflow workflow. For example:
This configuration contains a sample workflow. Every step has a text which you can use to display them.
All of the other necessary attributes has to be add to the extra array.
The property_path contains the column name in the table which stores the actual step of the record.
Usage
Step 1
First you need to add a new column to your Eloquent model table for example called: last_step/status or whatever you want.
In your config file property_path attribute has to be the same value than the column name.
Step 2
You have to add the Flowable trait to your Eloquent model to use the workflow.
Step 3
Than you have to add a function to your eloquent model called getLaraflowStates() .
This function has to return the array of the configuration!
Step 4
If you want to change the status of the Eloquent object you can use the
method which comes from the Flowable trait. The $new_status parameter is the value of the key attribute which comes from the getPossibleTransitions() function.
Events
You can listen to the 'global' events which fires in every status changes.
The PRE_TRANSITION fires before the status change, the POST_TRANSITION fires after. The CAN_TRANSITION fires when the package checks the transition is possible from the actual step. You can define callback(s) which will be call from the specified transition.
Validators
The package comes with a default validator class, which use the Laravel Validator class. You can add validation rules to the transitions, so the package can checks the Eloquent object attributes with the given rules before the transition. If the validation fails throws a LaraflowValidatorException exception with the error message(s) array.
You can define your own validator if you create a class which implements the LaraflowValidatorInterface.
Credits
This library has been highly inspired by https://github.com/winzou/state-machine.
License
The package is open-sourced software licensed under the MIT license.
All versions of laraflow with dependencies
illuminate/support Version 5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*
illuminate/database Version 5.6.* || 5.7.* || 5.8.*