Download the PHP package tamkeen-tech/laravel-enum-state-machine without Composer

On this page you can find all versions of the php package tamkeen-tech/laravel-enum-state-machine. 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 laravel-enum-state-machine

Latest Version on Packagist Total Downloads

Introduction

This package simplify controlling the transition between model states, allowing you to prevent unlogically transition and also controlling the initial state of the model using the PHP enums. Each enum allows you to define your states, the allowed transitions and the initial state, all in one place.

Laravel Enum State Machine, also allows you to automatically record the history of the state transition for each define state machine.

This package is built to help developers with the least amount of work needed to get it working.

Installation

You can install the package via composer:

Next, if you going to record the history

To publish the config file, you can use the following command:

Usage

Imagine you have bill with statuses, so at your bill model you will need to use HasStateMachines trait, and define your protected $stateMachines array variable to include all the fields that you going to apply the state machine on, and finally an optional variable protected $recordStateHistory boolean to either save history or not.

In your BillStatus class you need to use trait StateMachine and to add two methods transitions to define your transition array and initialState to define the allowed initial states, both must return array.

From the example above the allowed transitions for PENDING case are PAID and EXPIRED, and the initail state for bill must be only PENDING

Now you are all done, you can start writing your code safely. So now if your tried to create a bill with different state you will receive an exception.

Example

State History Recording

When you enable state history recording by setting protected $recordStateHistory = true in your model, the package will automatically track all state changes for the fields defined in $stateMachines.

Each state change will be recorded in the state_machine_histories table with the following information:

You can access the state history through the stateHistory relationship:

Flow Diagram Generation

You can generate a flow diagram of your state machine using the following command:

You can specify a custom output directory using the --output option

This command will create a visual representation of your state machine as a PNG file, making it easier to understand the transitions between states.

Helper Methods

The StateMachine trait provides several helper methods to make working with state transitions easier.

canTransitTo

This method checks if the current state can transition to a given state.

Example

inInitialState

This method checks if the current state is one of the allowed initial states.

Example

is

This method checks if the current state is equal to a given state.

Example

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

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


All versions of laravel-enum-state-machine with dependencies

PHP Build Version
Package Version
Requires laravel/framework Version ^10.0|^11.0
php Version ^8.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 tamkeen-tech/laravel-enum-state-machine contains the following files

Loading the files please wait ....