app->isLocal()) { $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class); } } /** * Bootstrap any application services. * * @return void */ public function boot() { // 实施验证类扩展 $this->validatorExtensions(); } /** * 实施验证类扩展 */ private function validatorExtensions() { foreach ($this->getValidatorRules() as $method) { $method = Str::snake($method); Validator::extend($method, function ($arruibute, $value, $paramters, $validator) use ($method) { return $this->getValidatorExtension()->{$method}($arruibute, $value, $paramters, $validator); }); } } /** * 获取扩展验证类实例 * @return ValidatorExtension */ private function getValidatorExtension() { if (!$this->validatorExtension instanceof ValidatorExtension) { $this->validatorExtension = new ValidatorExtension(); } return $this->validatorExtension; } /** * 获取验证实施规则 * @return array */ private function getValidatorRules() { return [ 'mobile', ]; } }