fhteam/laravel-validator
最新稳定版本:v2.4.0
Composer 安装命令:
composer require fhteam/laravel-validator
包简介
A bunch of Laravel validators
README 文档
README
| Metrics | _ |
|---|---|
| Version | |
| Compatibility | |
| Quality |
Features:
- Validation logic is completely separate from objects being validated
- Validation rules and validation failure behaviour can be written in a declarative way in 90% of cases
- Uses Laravel validator core and rules
- Stateful model validation
- Provides OOP way to write and register new validation rules
- Serves as a replacer to a Input::get() to prevent unvalidated data from sneaking into your application
- Rule-based data transformations of validated data before it reaches your application logic (in progress)
- Provides unified way to write rules for controllers and models
- Can validate and aggregate many types of input: $_GET/$_POST, $_FILES, HTTP headers, Session data, Cookies (both PHP native and Laravel's encrypted ones)
- Two types of input validators: middleware (to be manually registered) and validate-when-resolved (just inject and you are done)
Documentation
- Documentation is available here
Quick example:
class OrderControllerValidator extends FrontendControllerValidatorWhenResolved { protected $rules = [ '*' => [ 'user_id' => 'required|numeric', ], 'getCreate, getShow, getEdit' => [], 'postOpen, postDelete, postAssignContractor, postCancelContractorAssignment' => [], 'postCreate' => [ 'title' => 'required|max:100', 'categoryId' => 'required|numeric', 'description' => 'required|max:4096', ], 'postEdit, postFileDelete, postFileUpload' => [ 'title' => 'required|max:100', 'categoryId' => 'required|numeric', 'description' => 'required|max:4096', ], ]; protected $errorRedirects = [ 'getShow' => ['route' => 'home'], 'postCreate' => ['route' => 'orders_create'], 'postEdit, postFileUpload, postFileDelete' => ['route' => ['orders_edit', ['orderId' => '#orderId']]], ]; } class OrderController extends Controller { /** * @var OrderControllerValidator */ protected $validator; /** * IoC invoked constructor */ public function __construct(OrderControllerValidator $validator) { $this->validator = $validator; } public function getShowValidatedData() { return Response::make($this->validator->description); }
统计信息
- 总下载量: 775
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-only
- 更新时间: 2015-03-24