Download the PHP package androlax2/laravel-model-state-graph without Composer

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

Laravel Model State Graph

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

About

Laravel Model State Graph provides a powerful, flexible way to enforce complex business rules and state transitions in your Eloquent models. Instead of scattering validation logic across controllers, form requests, and model observers, this package lets you define field-level business rules that are conditionally applied based on your model's current state.

Think of it as a state machine for individual model fields, where you can control what changes are allowed, when they're allowed, and under what conditions.

When to Use

This package is ideal for scenarios where you need to:

Real-World Examples

Requirements

Installation

Install the package via composer:

Core Concepts

The package is built around three main interfaces:

BusinessRule Interface

Individual validation rules that can be conditionally applied:

FieldRuleSet Interface

Groups related business rules for a specific model field:

ModelStateGraph

Coordinates rule execution:

Quick Start

Let's start with the simplest possible example - validating a single field:

Step 1: Create a Business Rule

Step 2: Create a Field Rule Set

Step 3: Validate Your Model

Basic Usage

Multiple Rules for a Single Field

Conditional Business Rules

Rules that only apply in specific scenarios:

Validating Multiple Fields

Advanced Usage

Status Transition Rules

Control complex state machine workflows:

Conditional Rule Sets with Dependencies

Inject services and apply rules based on feature flags, user roles, or other context:

Complex Business Rules with External Dependencies

Integration with Laravel Events

You can integrate the graph into your model lifecycle using Laravel events:

Error Handling

The package provides specific exceptions for different error scenarios:

Testing

Testing Business Rules

Testing Field Rule Sets

Testing Full Validation

Best Practices

1. Keep Rules Focused and Single-Purpose

Each business rule should validate one specific concern:

2. Use supports() Efficiently

Skip expensive validation when rules don't apply:

3. Provide Clear, Actionable Violation Messages

Help users understand what went wrong and how to fix it:

4. Organize Rules by Model

Since RuleSets and Rules are tied to specific models, organize them by model for better clarity and maintainability:

This structure groups related rules by their field/concern, making it easy to find and maintain all rules for a specific field.

5. Leverage Dependency Injection

Use Laravel's container for flexibility and testability:

6. Test Thoroughly

Write tests for:

7. Document Your State Machines

When implementing complex status transitions, document them:

Performance Considerations

Comparison with Laravel Validation

Laravel Model State Graph complements Laravel's built-in validation but serves a different purpose:

Feature Laravel Validation Model State Graph
Use Case Request input validation Business logic validation
Context HTTP layer Model layer
State Awareness Limited Full state transition support
Conditional Logic Basic Complex, context-aware
Integration Form Requests Model lifecycle events

Use both together: Laravel validation for input sanitization, Model State Graph for business rule enforcement.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security Vulnerabilities

If you've found a bug regarding security please mail [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-model-state-graph with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/contracts Version ^10.0|^11.0|^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 androlax2/laravel-model-state-graph contains the following files

Loading the files please wait ...