Download the PHP package webrek/laravel-state-machine without Composer

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

Laravel State Machine

Latest Version on Packagist Total Downloads Tests PHP Version

Declarative state machines for Eloquent models. Define the states a model can be in and the transitions between them, and let the package guarantee that only valid transitions ever happen — with guards, events and an optional audit trail.

Quick start

Define a machine:

Bind it to a model attribute:

Use it:

Why a state machine instead of if statements

The state of an order, a subscription, a support ticket or a KYC request is rarely a free-form string: it's a set of named states with strict rules about which one can follow which. Encoding those rules as scattered if ($order->status === 'paid') checks means the rules live in a dozen places and nothing prevents an invalid jump like pending → delivered.

A state machine puts the rules in a single declaration and enforces them:

The handler API

$model->stateMachine($attribute) returns a handler. With a single machine the attribute is optional.

The context array passed to apply() reaches the guards and the dispatched events, and is stored alongside the history row.

Guards

A guard is a closure that receives the model and the context array. The transition is only allowed when it returns true.

can() returns false when a guard blocks it; apply() throws GuardFailedException.

Transition effects (atomic)

Attach a side effect to a transition with ->using(). It runs inside the same database transaction as the state change and the history record, so everything is all-or-nothing: if the effect throws an exception, the state never moves.

If payment->refund() throws an exception, the transition is rolled back — the order stays in paid, no history row is written and the in-memory model is restored. No half-applied transitions.

Diagram

Render any machine as a Mermaid state diagram:

Paste the output into a bash php artisan vendor:publish --tag=state-machine-migrations php artisan migrate env STATE_MACHINE_HISTORY=true bash composer install composer test



## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md).

## Security

Please review the [security policy](SECURITY.md) before reporting a
vulnerability.

## License

The MIT License (MIT). See [LICENSE](LICENSE).

All versions of laravel-state-machine with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/contracts Version ^12.0 || ^13.0
illuminate/database Version ^12.0 || ^13.0
illuminate/support Version ^12.0 || ^13.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 webrek/laravel-state-machine contains the following files

Loading the files please wait ...