Laravel 5 中自定义的validation放在什么位置比较好?
最近在论坛发现了个比较满意的方案。
# app/wherever-you-want/CustomValidator.php
<?php
class CustomValidator extends Illuminate\Validation\Validator {
public function validateFoo($attribute, $value, $parameters)
{
return $value == 'foo';
}
}
<?php
class AppServiceProvider extends ServiceProvider{
public function boot()
{
// ...
Validator::resolver(function($translator, $data, $rules, $messages)
{
return new CustomValidator($translator, $data, $rules, $messages);
});
// ...
}
}
References