Download the PHP package spatie/laravel-model-states without Composer
On this page you can find all versions of the php package spatie/laravel-model-states. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download spatie/laravel-model-states
More information about spatie/laravel-model-states
Files in spatie/laravel-model-states
Package laravel-model-states
Short Description State support for Eloquent models
License MIT
Homepage https://github.com/spatie/laravel-model-states
Informations about the package laravel-model-states
Adding state behaviour to Eloquent models
This package adds state support to models. It combines concepts from the state pattern and state machines.
It is recommended that you're familiar with both patterns if you're going to use this package.
To give you a feel about how this package can be used, let's look at a quick example.
Imagine a model Payment
, which has three possible states: Pending
, Paid
and Failed
. This package allows you to represent each state as a separate class, handles serialization of states to the database behind the scenes, and allows for easy state transitions.
For the sake of our example, let's say that, depending on the state, the color of a payment should differ.
Here's what the Payment
model would look like:
This is what the abstract PaymentState
class would look like:
Here's a concrete implementation of one state, the Paid
state:
And here's how it is used:
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
You can install the package via composer:
You can publish the config file with:
This is the content of the published config file:
Usage
Please refer to the docs to learn how to use this package.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you've found a bug regarding security please mail [email protected] instead of using the issue tracker.
Credits
- Brent Roose
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-model-states with dependencies
ext-json Version *
facade/ignition-contracts Version ^1.0
illuminate/contracts Version ^8.73 | ^9.0 | ^10.0 | ^11.0
illuminate/database Version ^8.73 | ^9.0 | ^10.0 | ^11.0
illuminate/support Version ^8.73 | ^9.0 | ^10.0 | ^11.0
spatie/laravel-package-tools Version ^1.9