Download the PHP package hpwebdeveloper/laravel-stateflow without Composer

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

Laravel StateFlow

Image

A modern, enterprise-ready state machine implementation for Laravel Eloquent models.

Author: Hamed Panjeh

Laravel StateFlow is inspired by similar concepts found in Spatie Laravel Model States, however, it is a fully independent, ground-up implementation with its own architecture and design decisions. It combines the state pattern with state machines to deliver enterprise-ready features: automatic state class discovery, automatic transition discovery, permissions, UI metadata, history tracking, and API resources. Laravel StateFlow maintains a single, unified topology of all possible states and transitions in your application's backing enum. This centralized architecture ensures that state definitions remain synchronized across your entire application, eliminating inconsistencies between backend logic and frontend representations. For large, complex systems, managing state changes and transitions is no longer cumbersome or bug-prone as your system growsβ€”a single enum serves as the definitive source of truth.

πŸ“¦ Demo Application: See Laravel StateFlow in action with a complete order management demo at laravel-stateflow-demo.

πŸ“š Table of Contents


Introduction

This package adds state support to your Eloquent models. It lets you represent each state as a separate class, handles serialization to the database behind the scenes, and provides a clean API for state transitions with full authorization and audit capabilities.

Example: Imagine an Order model with states: Pending, Processing, Shipped, Delivered, and Cancelled. Each state can have its own color for UI, permitted roles for authorization, and the transitions between them are explicit and validated.

Why Laravel StateFlow?

The Problem: Manual State Management in Legacy Systems

In traditional Laravel applications, state management is typically handled with simple string columns and scattered conditional logic:

πŸ€¦β€β™‚οΈ This creates several pain points:

Scattered Workflow Definition

Frontend/Backend Synchronization Gap

Missing Enterprise Features

Data & Querying Limitations

Testing & Maintenance Burden

Laravel-StateFlow's Solution: Centralized State Topology

StateFlow supports two approaches for defining your state machine:

Approach Best For Transitions Defined In
Traditional Self-contained states, IDE navigation State classes or model
Hybrid Enum Centralized workflow visualization Single enum file

Both approaches are demonstrated in the laravel-stateflow-demo: Orders (traditional) and Bookings (enum).

Laravel StateFlow solves this with centralized workflow definition β€” see your entire state machine at a glance:

πŸ’‘ See it live: BookingStateStatus.php ・ Booking.php ・ Docs

⭐️⭐️⭐️⭐️⭐️ Key Innovations

Laravel StateFlow provides enterprise features like automatic state discovery, rich UI metadata, built-in permissions, complete audit trails, and seamless Eloquent integration:

Feature βœ“ Description Example
Generate enum from states βœ… Create workflow enum from existing state classes php artisan stateflow:sync-enum ・ Docs
Automatic next states βœ… Discover available transitions from current state OrderController.php ・ Docs
UI metadata βœ… Colors, icons, titles for frontend integration Pending.php ・ Docs
Eloquent integration βœ… Cast-based approach with clean, Laravel-native syntax Order.php
Role-based permissions βœ… Control transitions by user roles Processing.php ・ Docs
Policy-based permissions βœ… Use Laravel policies for transition authorization OrderPolicy.php ・ Docs
State history & audit βœ… Complete transition history with performer tracking OrderController.php#show ・ Docs
API Resources βœ… Ready-to-use JSON responses for states Docs
Advanced query scopes βœ… orderByState, countByState, averageTimeInState Docs
Silent transitions βœ… Transition without firing events Docs
Force transitions βœ… Bypass validation for admin overrides Docs
Fluent transition API βœ… Clean, chainable API for transitions Docs
Centralized enum transitions βœ… Define state topology in a single enum for clarity BookingStateStatus.php ・ Docs

Installation

Publish the config (optional):

For history tracking, publish and run migrations:


Preparation in 4 simple Steps

1. Add State Column to Your Model

Add a state column to the model that will have state transitions. For example, if you have an Order model:

Note: Replace orders with your table name (e.g., posts, invoices, tickets).

2. Create State Classes

Generate all state classes at once using the --states option:

This single command creates the base class and all extending state classes:

Alternative: You can also create states individually:

πŸ’‘ See the demo: The laravel-stateflow-demo uses this structure β€” see States/Order/ for a complete example.

⚠️ Important: Keep all state classes in the same directory as their base state class. When adding new states later, use the full namespace:

The stateflow:sync-enum command only discovers states in the same directory as the base class.

3. Configure States

3.1 Traditional Approach β€” State Classes with Metadata

StateFlow supports multiple approaches for defining state metadata: Methods, Attributes, and Constants. The demo uses a combined approach β€” attributes for static metadata (title, description) and methods for dynamic values (color(), icon()).

πŸ’‘ See the demo: Pending.php and States/Order/

3.2 Hybrid Enum Approach β€” Centralized Workflow Topology

For teams who prefer seeing the entire workflow at a glance, use an enum to define the transition topology. State classes still handle behavior (colors, icons, metadata).

The Enum β€” Shows all transitions in one place:

State classes remain simple (behavior only, no transitions):

πŸ’‘ See the demo: BookingStateStatus.php and States/Booking/

πŸ“š Learn more: See Defining States and Transitions for detailed comparison of all approaches.

4. Add to Model

4.1 Traditional Approach β€” Explicit Transitions

πŸ’‘ See the demo: Order.php

4.2 Hybrid Enum Approach β€” Clean & Elegant ✨

With the enum approach, your model becomes remarkably clean:

Benefits of the enum approach:

πŸ’‘ See the demo: Booking.php

πŸ“š Learn more: See Defining States and Transitions for all approaches.


Optional: Generate Enum & History Tracking

Generate enum from existing state classes:

Naming Convention: By default, the command creates {BaseStateClass}Status (e.g., OrderState β†’ OrderStateStatus). Use --enum=App\Enums\YourCustomName to specify a different name.

⚠️ Directory Requirement: The sync command only discovers state classes in the same directory as the base state class. If you add new states later, ensure they are in the correct directory (e.g., app/States/Order/ for OrderState).

Enable history tracking: Add ->recordHistory() to your StateConfig and use the HasStateHistory trait. See History Tracking.


How to use it

Basic Usage

πŸ’‘ Full Example: See the laravel-stateflow-demo for a complete implementation β€” Order.php (model), OrderController.php (controller), and States/Order/ (state classes).

Serializing States

States are stored in the database using their NAME constant value:

Tip: You can use class names (e.g., Processing::class) throughout your code - the package handles mapping to/from database values.

Listing Registered States

Retrieving Transitionable States

Using States in Blade Templates


Transitions

Basic Transition

With Metadata

Fluent API

Silent Transition (No Events)

Force Transition (Skip Validation)


Permissions

StateFlow provides flexible permission control through role-based and policy-based authorization. Control who can perform state transitions based on user roles, ownership, or complex business logic.

πŸ“– Complete Permissions Documentation

Quick example:


History Tracking

Enable History

Query History

History Record

πŸ’‘ See it in action: The demo shows complete history tracking with a timeline UI β€” see OrderController.php for how history is queried and formatted.


API Resources

State Resource

In Controller


Query Scopes


Validation Rules


Events

Event Properties


Artisan Commands

🌟 Key Feature: The stateflow:sync-enum command scans your state directory and generates a workflow enum with all discovered states. This creates an enum with stateClasses(), canTransitionTo(), and transitions() methods ready for use in your model's registerStates() method.


Configuration Reference


Common Patterns

Order Workflow

πŸ’‘ See this in action: The laravel-stateflow-demo demonstrates this workflow β€” see Order.php for the model and OrderController.php for the controller implementation.

Multiple State Fields

Custom Transition Logic

Register in config:

Dependency Injection in Transitions

The handle() method supports dependency injection via Laravel's container:

This allows for clean separation of concerns and easier testing through dependency mocking.


Version Compatibility

Package Version Laravel Versions PHP Versions Status
1.x 12.x 8.3+ Active support

Note: The package is currently built for Laravel 12 with PHP 8.3+. Support for earlier Laravel versions may be added in future releases.


Credits

License

The MIT License (MIT). See License File for more information.


All versions of laravel-stateflow with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/support Version ^12.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 hpwebdeveloper/laravel-stateflow contains the following files

Loading the files please wait ...