请尝试以下操作:
- 创建一个绑定类,您可以在其中实现要扩展的每个规则
Validator
。 - 使服务提供商扩展
ServiceProvider
。 - 在
config/app.php
文件中添加您的自定义验证程序提供程序。
您可以在以下
Services文件夹中创建绑定:
namespace MyAppServices;class Validator extends IlluminatevalidationValidator{ public function validateFoo($attribute, $value, $parameters){ return $value == "foo" }}然后,使用服务提供商来扩展核心:
namespace MyAppProviders;use MyAppServicesValidator;use IlluminateSupportServiceProvider;class ValidatorServiceProvider extends ServiceProvider{ public function boot() { Validator::resolver(function($translator, $data, $rules, $messages) { return new Validator($translator, $data, $rules, $messages); }); } public function register() { }}最后,按如下所示导入服务提供商
config/app.php:
'providers' => [ ... ... 'MyAppProvidersValidatorServiceProvider';]



