Download the PHP package lenderspender/laravel-state-transition-workflow without Composer

On this page you can find all versions of the php package lenderspender/laravel-state-transition-workflow. 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-state-transition-workflow

Laravel State Transitions Workflow

This package adds state transitions workflows to your Laravel models. Allowing you to specify transitions and how to act on those transitions.

To show you how to use this package, let's sketch the following scenario.

A transaction can have three states CREATED, FAILED and SUCCESS. When transitioning between states you probably want to act on this transition e.g. send a success email. You probably only want to allow transitions from SUCCESS to FAILED and not the other way around.

The transaction model would look like:

Here is what the TransactionState enum looks like:

And here is what the TransactionSuccessfullWorkflow could look like:

And here is how you use it:

Installation

You can install the package via composer:

Usage

The package provides a HasStateTransitions trait which you can use in any model where you want to support state.

State management

Registering state field

To setup states for the $status attribute you should add the HasStateTransitions trait to the model and implement the registerStateTransitions method.

Adding allowed transitions

Transitions are used to transition the state field for a model from one to another. You need to specify which transitions are allowed and what workflow should be started on transition. By default all transitions are not allowed, to allow transitions you should call allowTransition on the added state.

Single transition from State::FROM() to State::TO()

Allow transitions from State::CREATED() to State::FAILED() and State::SUCCESS()

Allow transitions from State::CREATED() and State::UPDATED() to State::FAILED() and State::SUCCESS()

Using transitions

Transitions can be used by calling the transitionStateTo method on the model.

By default the method uses the first registered state. When you've added multiple state fields you should specify which field to use.

When a state transitions is not allowed a LenderSpender\StateTransitionWorkflow\Exceptions\TransitionNotAllowedException is thrown.

Listing allowed state transitions

To know what allowed state transitions can be performed you could call the getAvailableStateTransitions on the model.

By default the method uses the first registered state. When you've added multiple state fields you should specify which field to use.

State workflows

When transitioning a model from one state to another you sometimes want to act on this transition. Or even prevent the transition from happening. That's where state workflows come into place.

Creating a workflow

Automatically handle the transition after workflow execution

Handle the transition in the workflow

Queuing transitions

When you want to perform some heavy actions before or after the transition you could queue the transition by implementing the ShouldQueue interface on the workflow.

Preventing transitions

Transitions can be prevented when you override the isAllowed method and return false in the workflow.

Registering a workflow to a state transition


All versions of laravel-state-transition-workflow with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
laravel/framework Version ^11.0 | ^10.0
spatie/laravel-queueable-action Version ^2.14
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 lenderspender/laravel-state-transition-workflow contains the following files

Loading the files please wait ....