raid/core-request
Composer 安装命令:
composer require raid/core-request
包简介
Raid Core Request Package
README 文档
README
This package is responsible for handling all requests in the system.
Installation
composer require raid/core-request
Configuration
php artisan core:publish-request
Usage
use App\Traits\Request\WithUserCommonRules; use Raid\Core\Request\Requests\FormRequest; class CreateUserRequest extends FormRequest { use WithUserCommonRules; /** * Get the validation rules that apply to the request. */ public function rules(): array { return $this->withCommonRules(); } }
How to work this
Let's start with our request class CreateUserRequest.
you can use the command to create the request class.
php artisan core:make-request CreateUserRequest
<?php namespace App\Http\Requests; use Raid\Core\Request\Requests\FormRequest; class CreateUserRequest extends FormRequest { /** * Get the validation rules that apply to the request. */ public function rules(): array { return []; } }
This looks like a normal request class, but it's not it just needs some helper.
The request class MUST extend the FormRequest class.
Now, let's create our common-rules-request trait.
you can use the command to create the common request trait.
php artisan core:make-common-request WithUserCommonRules
<?php namespace App\Traits\Request; trait WithUserCommonRules { /** * Get the common rules for the request. */ public function commonRules(): array { return []; } /** * Get the common attributes for the request. */ public function attributes(): array { return []; } }
The commonRules method is responsible for returning the common rules for the request.
you can define the rules that are common for your request and their attributes.
<?php namespace App\Traits\Request; trait WithUserCommonRules { /** * Get the common rules for the user. */ public function commonRules(): array { return [ 'name' => ['string', 'min:2', 'max:255'], ]; } /** * Get the common attributes for the user. */ public function attributes(): array { return [ 'name' => __('attributes.name'), ]; } }
With Common Rules
Now let's go back to our request classes.
<?php namespace App\Http\Requests; use Raid\Core\Request\Requests\FormRequest; use App\Traits\Request\WithUserCommonRules; class CreateUserRequest extends FormRequest { use WithUserCommonRules; /** * Get the validation rules that apply to the request. */ public function rules(): array { return $this->withCommonRules([ 'name' => ['required'], ]); } }
<?php namespace App\Http\Requests; use Raid\Core\Request\Requests\FormRequest; use App\Traits\Request\WithUserCommonRules; class UpdateUserRequest extends FormRequest { use WithUserCommonRules; /** * Get the validation rules that apply to the request. */ public function rules(): array { return $this->withCommonRules([ 'name' => ['sometimes'], ]); } }
Now both requests inherit the common rules and attributes for all the common rules defined, and each one has its own rules as well.
The withCommonRules method is responsible for merging the common rules with the request rules.
The withCommonRules method accepts an array of rules, and it will merge it with the common rules.
Remember that all the common rules will be inherited by all the requests that use the common rules' trait.
With Only Common Rules
To only merge the common rules with the request rules, you can use the withOnlyCommonRules method.
<?php namespace App\Http\Requests; use Raid\Core\Request\Requests\FormRequest; use App\Traits\Request\WithUserCommonRules; class CreateUserRequest extends FormRequest { use WithUserCommonRules; /** * Get the validation rules that apply to the request. */ public function rules(): array { return $this->withOnlyCommonRules([ 'name' => ['required'], ]); } }
The withOnlyCommonRules method is responsible for merging the common rules with the request rules and ignoring all other rules.
This will merge only the name rules with the common rules for name, and ignore all other common rules defined.
And that's it.
License
The MIT License (MIT). Please see License File for more information.
Credits
Security
If you discover any security-related issues, please email instead of using the issue tracker.
About Raid
Raid is a PHP framework created by Mohamed Khedr
and it is maintained by Mohamed Khedr.
Support Raid
Raid is an MIT-licensed open-source project. It's an independent project with its ongoing development made possible.
raid/core-request 适用场景与选型建议
raid/core-request 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 08 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「validation」 「request」 「laravel」 「core」 「raid」 「form-request」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 raid/core-request 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 raid/core-request 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 raid/core-request 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
HTTP request logger middleware for Laravel
Adds request-parameter validation to the SLIM 3.x PHP framework
A jQuery augmented PHP library for creating and validating HTML forms
A Laravel validator for delimiter-separated list of emails.
A CakePHP behavior to validate foreign keys
PHP Validator for stuff.
统计信息
- 总下载量: 30
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-31