PHPackages                             weiwenhao/state-machine - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. weiwenhao/state-machine

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

weiwenhao/state-machine
=======================

state machine

0.2.5(7y ago)663943[1 issues](https://github.com/green-lizard/state-machine/issues)[1 PRs](https://github.com/green-lizard/state-machine/pulls)MITPHP

Since Jun 21Pushed 6y agoCompare

[ Source](https://github.com/green-lizard/state-machine)[ Packagist](https://packagist.org/packages/weiwenhao/state-machine)[ RSS](/packages/weiwenhao-state-machine/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (4)Versions (9)Used By (0)

介绍
--

[](#介绍)

> 基于laravel model的状态管理扩展

开发中经常需要为实体定义一些状态 如对于文章实体可能会有 new/draft/deleted 对于支付实体可能会有 awaiting\_payment/cancelled/paid/refunded

对于订单实体↓

[![](https://camo.githubusercontent.com/f03888c970957a11d3bf1782a67b3f94b3642a62882d717b3564cffc010b5ea9/687474703a2f2f61737365742e6569656e616f2e636f6d2f31353239363534373836323733382e6a7067)](https://camo.githubusercontent.com/f03888c970957a11d3bf1782a67b3f94b3642a62882d717b3564cffc010b5ea9/687474703a2f2f61737365742e6569656e616f2e636f6d2f31353239363534373836323733382e6a7067)

对于小程序的的迭代周期实体可能会有 ↓ [![](https://camo.githubusercontent.com/754ea31bde01e311591c56d36bb7b40a3e4a386993f60427707d563d213093d6/687474703a2f2f61737365742e6569656e616f2e636f6d2f31353239363534383237373038382e6a7067)](https://camo.githubusercontent.com/754ea31bde01e311591c56d36bb7b40a3e4a386993f60427707d563d213093d6/687474703a2f2f61737365742e6569656e616f2e636f6d2f31353239363534383237373038382e6a7067)

面对开发过程中繁杂的状态,我们需要一个状态管理工具. 而state-machine就是管理状态之间转换的一个laravel扩展,拥有优雅的语法与回调机制.

安装
--

[](#安装)

```
composer require weiwenhao/state-machine

```

> 支持laravel5.5+版本

创建graph
-------

[](#创建graph)

`php artisan make:graph TestGraph`

运行该命令将会在`app\Graphs`目录下创建一个TestGraph文件. 如果你不明白如何配置 graph,则可以运行 `php artisan make:graph TestGraph -demo` 来生成一个demo.

```
