dsxwk/hyperf-helper
最新稳定版本:v1.1.0
Composer 安装命令:
composer require dsxwk/hyperf-helper
包简介
Hyperf Framework Assistant
README 文档
README
安装
composer require dwxwk/hyperf-helper
验证器
继承
BaseFormRequest类,实现sceneRule方法,返回验证场景规则, 支持每个场景自定义字段验证,满足更复杂验证。官方的公共rules方法,无法满足复杂验证场景。如创建某个字段必填,但是更新相同的字段又不需要验证或者使用其他验证,增加了灵活性。
<?php declare(strict_types=1); namespace App\Request; use Dsxwk\Framework\HyperfHelper\Request\BaseFormRequest; class IndexRequest extends BaseFormRequest { /** * 验证场景规则 * * @return array */ public function sceneRules(): array { return [ // 创建 'create' => [ 'remark' => 'nullable|string', 'attachments' => 'array', // ... ], // 更新 'update' => [ 'id' => 'required|integer|gt:0', 'remark' => 'nullable|string', 'attachments' => 'array', // ... ], ]; } /** * 提示字段设置 * * @return string[] */ public function attributes(): array { return [ 'id' => 'ID', 'remark' => '备注', 'attachments' => '附件', ]; } }
控制器
<?php declare(strict_types=1); namespace App\Controller; use App\Request\IndexRequest; use Hyperf\Di\Annotation\Inject; class IndexController { #[Inject] public IndexRequest $indexRequest; public function create() { // 验证场景 $this->indexRequest->scene('create')->validateResolved(); // ... } public function update() { // 验证场景 $this->indexRequest->scene('update')->validateResolved(); // ... } }
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2025-11-02