asz/statemm
Composer 安装命令:
composer require asz/statemm
包简介
manage model state
README 文档
README
Overview
- This is a Laravel package to manage model state
Installation :
You can install asz/statemm via Composer by adding " asz/statemm": "^1.1"
as requirement to your composer.json.
OR :
composer require asz/statemm
- Then :
composer dump-autoload
Service Provider:
go to your config/app.php file and add :
statemm\StateServiceProvider::class ,
adding interface to model
class Product extends Model implements hasState
use command line to create a new state for your model
$ php artisan state:make activated --dir=productStateContainer
add method stubs in your model: public function initialState() { //set your initial state after generated // TODO: Implement initialState() method. return new ActivatedState(); }
Test Unit
public function testCanDeactivateProduct() { $product = new product(); // the product is active and the initial state will check to // $this->transitionTo( new DeactivatedState()); $context = new Context($product->where(['id' => 4])->first()); // if true the proceed function will go to next state // which is deactivatedState and execute the query or what // you want todo // the deactivated has query to deactivate the given product $context->proceed(); self::assertEquals(StateEnum::DEACTIVATED_STATE, $context->getModel()->state); } ```
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-07-16