dsxwk/hyperf-helper

There is no license information available for the latest version (v1.0.0) of this package.

Hyperf Framework Assistant

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/dsxwk/hyperf-helper

v1.0.0 2025-09-30 03:43 UTC

This package is not auto-updated.

Last update: 2025-10-01 02:17:41 UTC


README

安装

composer require dwxwk/hyperf-helper

验证器增强, 无需控制器引入自动识别当前请求方法,无需引入验证场景通过当前请求方法自动识别

验证器

<?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;

class IndexController
{
    public function create()
    {
        // ...
    }
    
    public function update()
    {
        // ...
    }
}