flipjms/laravel-scenarios
Composer 安装命令:
composer require flipjms/laravel-scenarios
包简介
An easier way to put your application into different states for easy debugging/development
README 文档
README
This little package helps you set your Laravel application into a given state/scenario.
Let's say that you want to finally fix that pesky edge case bug and for that you need to have your application in a very specific state. Example:
- you need to have a user with role X
- your user needs to have bought two products
- the payment for the second product needs to have status Y
- Another condition
- Extra condition
- Last condition
With this package you can create a new Scenario, write the code needed to have the application in the state above, and run the command to set the scenario.
Voilá! Now you have a nice file descriptive file that sets your application into the right state so you can easily develop against and reset everytime you need it.
Not only that, but it also makes it easy for other people to quickly check which scenarios are available, and use them.
Installation
You can install the package via composer:
composer require flipjms/laravel-scenarios
Go to you composer.json and add the following:
"autoload": { "psr-4": { "Database\\Scenarios\\": "database/scenarios/" } },
Usage
To create a new scenario:
php artisan make:scenario NewScenarioName
Be descriptive with your names. Do not be afraid of long names.
The file will be created at ./database/scenarios/
Set an alias and a nice description for it. Then on the execute method add the necessary code to place your
application into the desired state. Usually you do that by running factories, seeders, etc...
The output method allows you to output information to the console once the scenario has been set. This is useful to
display information that you might need, like a user login, or an url that you might need to visit.
All the Laravel Output IO commands are available apart from the
progress bar.
You can also use Termwind for a prettier output.
To set a scenario
php artisan scenarios:set or php artisan scenarios:set scenario-alias
More often than not, you want to clean your database. If that's the case, you can use the --fresh option:
php artisan scenarios:set --fresh or php artisan scenarios:set scenario-alias --fresh
Questions
- Why not just use seeders?
- IMHO seeders are nice to put your application into a default state not specific ones.
- Why not use commands?
- You can definitely use commands. I've certainly done so. Nonetheless, I like to see commands as business logic, whereas scenarios is something you need while developing/debugging. This way I can keep my commands folder clean, and my scenarios neatly organized in their own folder.
Credits
License
The MIT License (MIT). Please see License File for more information.
flipjms/laravel-scenarios 适用场景与选型建议
flipjms/laravel-scenarios 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34.57k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 08 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「laravel-scenarios」 「flipjms」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 flipjms/laravel-scenarios 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 flipjms/laravel-scenarios 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 flipjms/laravel-scenarios 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
Laravel Dynamic Validation Scenarios
Laravel package for Accurate Online API integration.
Shared RCX Laravel DataTables UI and configuration helpers.
Boot a Laravel project on any machine with one command: app:serve installs missing tools (PHP, Node, Composer, Herd, Docker), creates .env, sets up the database, runs migrations, builds assets, starts a queue worker and serves via Herd, Sail or artisan serve; app:down cleanly stops everything it sta
Branded, diagnostic error pages (500, 403, 404, 419, 503) for Filament — native Filament UI, dark mode and translations out of the box.
统计信息
- 总下载量: 34.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-08-22