kakaprodo/custom-data
Composer 安装命令:
composer require kakaprodo/custom-data
包简介
A Laravel package that wraps function arguments together into a single CustomData class allowing separate processing and validation for each argument.
README 文档
README
Official Documentation
A Laravel package that wraps function arguments together into a single CustomData class allowing separate processing and validation for each argument.
class CreateUserData extends CustomData { protected function expectedProperties(): array { return [ 'name' => $this->dataType()->string(), 'email' => $this->dataType()->string(), 'password' => $this->dataType()->string(), 'age?' => $this->dataType()->string(), 'sexe' => $this->dataType()->inArray(['M','F']) ]; } }
And then call it this way:
CreateUserData::make([ 'name' => 'kakaprodo', 'email' => 'example@gmail.com', 'password' => 'is_unique_pass', 'sexe' => 'M' ]);
And if you like to decouple your code with small classes called Action , then you are at the right place:
class CreateUserAction extends CustomActionBuilder { public function handle(CreateUserData $data) { return $data->onlyValidated(); } }
And then we call our action this way:
CreateUserAction::process([ 'name' => 'kakaprodo', 'email' => 'example@gmail.com', 'password' => 'is_unique_pass', 'sexe' => 'M' ]);
Features
- Combine several function arguments into one class called CustomData
- Validate each argument a little bit the way TypeScript does it in Javascript
- Support the definition of Laravel FormValidation rules
- Support Action classes in which CustomData can be injected
- Support The Ability to Queue Action class
- Support helper command to generate Action and CustomData classes
You can find here the Official Documentation
统计信息
- 总下载量: 4.16k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 2
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-28