From c8afaf01dc7a7a7c2392274ea47e937cc3827945 Mon Sep 17 00:00:00 2001 From: Anne Datema Date: Mon, 12 Jul 2021 14:23:25 +0200 Subject: [PATCH 1/2] Fix #27 validation rules are not deferred --- composer.json | 3 +- src/package/ServiceProvider.php | 22 +------------ src/package/ValidationServiceProvider.php | 40 +++++++++++++++++++++++ 3 files changed, 43 insertions(+), 22 deletions(-) create mode 100644 src/package/ValidationServiceProvider.php 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 From 16a6f4be95f93cf255005f2cbf20355835abce40 Mon Sep 17 00:00:00 2001 From: Anne Datema Date: Mon, 12 Jul 2021 14:27:49 +0200 Subject: [PATCH 2/2] Line ending as end of file --- src/package/ValidationServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package/ValidationServiceProvider.php b/src/package/ValidationServiceProvider.php index 50847f0..9aacd3d 100644 --- a/src/package/ValidationServiceProvider.php +++ b/src/package/ValidationServiceProvider.php @@ -37,4 +37,4 @@ protected function addValidators() }, 'The :attribute must be a valid '.$ruleName.'.'); } } -} \ No newline at end of file +}