diff --git a/composer.json b/composer.json index 210dfa0..c09de18 100644 --- a/composer.json +++ b/composer.json @@ -64,7 +64,8 @@ "extra": { "laravel": { "providers": [ - "PragmaRX\\CountriesLaravel\\Package\\ServiceProvider" + "PragmaRX\\CountriesLaravel\\Package\\ServiceProvider", + "PragmaRX\\CountriesLaravel\\Package\\ValidationServiceProvider" ], "aliases": { "Countries": "PragmaRX\\CountriesLaravel\\Package\\Facade" diff --git a/src/package/ServiceProvider.php b/src/package/ServiceProvider.php index 5745a95..e03dc61 100644 --- a/src/package/ServiceProvider.php +++ b/src/package/ServiceProvider.php @@ -3,7 +3,6 @@ namespace PragmaRX\CountriesLaravel\Package; use Illuminate\Support\Facades\Route; -use Illuminate\Support\Facades\Validator; use Illuminate\Support\ServiceProvider as IlluminateServiceProvider; use PragmaRX\Countries\Package\Countries as CountriesService; use PragmaRX\Countries\Package\Data\Repository; @@ -12,7 +11,6 @@ use PragmaRX\Countries\Package\Services\Helper; use PragmaRX\Countries\Package\Services\Hydrator; use PragmaRX\CountriesLaravel\Package\Console\Commands\Update; -use PragmaRX\CountriesLaravel\Package\Facade as CountriesFacade; class ServiceProvider extends IlluminateServiceProvider { @@ -62,9 +60,7 @@ protected function mergeConfig() */ public function boot() { - if (config('countries.validation.enabled')) { - $this->addValidators(); - } + // } /** @@ -129,22 +125,6 @@ protected function registerService() }); } - /** - * Add validators. - */ - protected function addValidators() - { - foreach (config('countries.validation.rules') as $ruleName => $countryAttribute) { - if (is_int($ruleName)) { - $ruleName = $countryAttribute; - } - - Validator::extend($ruleName, function ($attribute, $value) use ($countryAttribute) { - return ! CountriesFacade::where($countryAttribute, $value)->isEmpty(); - }, 'The :attribute must be a valid '.$ruleName.'.'); - } - } - /** * Register update command. */ diff --git a/src/package/ValidationServiceProvider.php b/src/package/ValidationServiceProvider.php new file mode 100644 index 0000000..50847f0 --- /dev/null +++ b/src/package/ValidationServiceProvider.php @@ -0,0 +1,40 @@ +addValidators(); + } + } + + /** + * Add validators. + */ + protected function addValidators() + { + foreach (config('countries.validation.rules') as $ruleName => $countryAttribute) { + if (is_int($ruleName)) { + $ruleName = $countryAttribute; + } + + Validator::extend($ruleName, function ($attribute, $value) use ($countryAttribute) { + return ! CountriesFacade::where($countryAttribute, $value)->isEmpty(); + }, 'The :attribute must be a valid '.$ruleName.'.'); + } + } +} \ No newline at end of file