Download the PHP package innoge/laravel-enum-states without Composer

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

Laravel Enum States

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A state machine for Eloquent, built on native PHP enums.

Your states stay plain enum cases and your models keep their normal casts. The transition graph lives on the enum itself, and fields are registered with a single attribute. No state classes, no model trait, no extra tables.

Why this exists

We wanted a state machine that feels native to Laravel, one you can drop into an API, SPA, Livewire, or Filament app without it fighting the rest of your stack. Most packages model states as objects, so the moment you serialize one to JSON, hydrate it in a Livewire component, or bind it to a Filament field, every layer has to learn about a new type. Here a state is just a native enum: it casts, serializes, and validates everywhere Laravel already understands enums, with nothing extra to register and nothing custom to serialize. One #[StateMachine] attribute on your model, the transition graph on the enum, and you're done.

Installation

Laravel Enum States requires PHP 8.3 or higher and Laravel 12 or 13.

Quick start

1. Cast the field and register it with the #[StateMachine] attribute.

2. Define the transition graph on the enum.

3. Transition with normal enum assignment.

The transition is validated when the model is saved. An invalid transition throws InvalidStateTransition, and the default is applied on save when the field is null.

Transitions

allow() accepts a single state or an array on either side, so one call can express one-to-one, one-to-many, many-to-one, or many-to-many transitions:

Actions

Actions run after the model is saved. Attach them to a specific transition, or to entering or leaving any state. They can be invokable classes or closures:

Class-based actions are resolved through Laravel's container, so you can inject any dependency:

Actions receive model, from, to, field, and context, plus any other type-hinted dependency the container can resolve. When a transition has all three kinds, they run in order: leaving actions, then entering actions, then transition-specific actions.

To pass context into your actions, use the enum method instead of plain assignment:

Additional named arguments arrive as the $context array on every action for that transition.

The field name is required because enum cases are singletons and do not know which model attribute returned them:

The field argument selects the model field and is not included in the action context.

Helpers

Check transitions from a model's current state, or statically from any state:

Build option lists for a frontend with StateOptions:

If a case has a getLabel() method, for example through Filament's HasLabel contract, that label is used automatically.

Filament select field
Install `filament/forms` and use `EnumStateSelect` instead of building options by hand. The current and reachable states are enabled; everything else is disabled: By default the field reads the live Livewire state. To base the options on the persisted record instead, pass the current state explicitly:
Validating transitions in form requests
Use the `ValidStateTransition` rule to reject invalid transitions before saving: Backed enums are validated by the submitted value; pure enums by the submitted case name.
How saving, events, and transactions work
Guarantees are enforced through Eloquent model events. Validation and defaults run on the `saving` event; actions run on the `saved` event. When the save is already transactional (`saveOrFail()` or an explicit `DB::transaction()`), actions run inside that transaction. Bulk query updates (`Order::where(...)->update(...)`) and quiet saves bypass model events, so they are **not** validated by this package. Queries already understand enum values, so no helper is needed for reads:

How it compares

This package is for teams who want a state machine that stays close to native PHP enums and Eloquent: the transition graph on the enum, fields wired up with an attribute, and no extra tables unless you add them. The trade-off to weigh is state-as-enum vs. state-as-object: enums serialize and validate across an API, SPA, Livewire, or Filament for free, while state-object approaches give each state its own class to hang behavior on but need extra handling to cross those boundaries. If you need per-state behavior classes, persisted history, or diagrams out of the box, one of the alternatives below may fit better.

Package States defined as Per-state classes History table Notes
innoge/laravel-enum-states Native enum + fluent graph No No Attribute on the model, no trait; actions with DI; validation + Filament helpers
spatie/laravel-model-states A class per state Yes No The state pattern in full, great when each state carries its own behavior, at the cost of more classes to write and register
asantibanez/laravel-eloquent-state-machines State-machine class per field No Yes Built-in persisted history, responsible user, and scheduled/postponed transitions; more setup and tables
sebdesign/laravel-state-machine Config arrays (Symfony Workflow) No No Framework-agnostic and works on any subject, but the graph lives in config rather than a type-safe enum
TamkeenTech/laravel-enum-state-machine Native enum (transitions() via match) No Yes Closest in spirit; ships DB history and diagram generation, but requires a HasStateMachines trait and has no enter/leave or per-transition actions

Testing

License

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


All versions of laravel-enum-states with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/contracts Version ^12.0||^13.0
illuminate/database Version ^12.0||^13.0
illuminate/support Version ^12.0||^13.0
spatie/laravel-package-tools Version ^1.16
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 innoge/laravel-enum-states contains the following files

Loading the files please wait ...