From 6f2c936a73da7790e839e095ecb2207124054132 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Sun, 1 Jul 2018 21:06:52 +0300 Subject: [PATCH] fixed #402 --- app/Http/Requests/Request.php | 25 ----------- app/Providers/ValidationServiceProvider.php | 46 +++++++++++++++++++++ config/app.php | 1 + 3 files changed, 47 insertions(+), 25 deletions(-) create mode 100644 app/Providers/ValidationServiceProvider.php diff --git a/app/Http/Requests/Request.php b/app/Http/Requests/Request.php index cf5d4827c..65f4ad8fa 100644 --- a/app/Http/Requests/Request.php +++ b/app/Http/Requests/Request.php @@ -2,36 +2,11 @@ namespace App\Http\Requests; -use App\Models\Setting\Currency; - use Illuminate\Foundation\Http\FormRequest; -use Illuminate\Validation\Factory as ValidationFactory; class Request extends FormRequest { - private $currency_code; - - public function __construct(ValidationFactory $validation) - { - $validation->extend( - 'currency', - function ($attribute, $currency_code, $parameters) { - $currency = false; - $currencies = Currency::enabled()->pluck('name', 'code')->toArray(); - - if (array_key_exists($currency_code, $currencies)) { - $currency = true; - } - - $this->currency_code = $currency_code; - - return $currency; - }, - trans('validation.custom.invalid_currency', ['attribute' => $this->currency_code]) - ); - } - /** * Set the company id to the request. * diff --git a/app/Providers/ValidationServiceProvider.php b/app/Providers/ValidationServiceProvider.php new file mode 100644 index 000000000..3e72e507c --- /dev/null +++ b/app/Providers/ValidationServiceProvider.php @@ -0,0 +1,46 @@ +pluck('name', 'code')->toArray(); + + if (array_key_exists($value, $currencies)) { + $status = true; + } + + $currency_code = $value; + + return $status; + }, + trans('validation.custom.invalid_currency', ['attribute' => $currency_code]) + ); + } + + /** + * Register any application services. + * + * @return void + */ + public function register() + { + // + } +} diff --git a/config/app.php b/config/app.php index f5bf9ecaa..6bedfcac7 100644 --- a/config/app.php +++ b/config/app.php @@ -178,6 +178,7 @@ return [ App\Providers\FormServiceProvider::class, App\Providers\ObserverServiceProvider::class, App\Providers\RouteServiceProvider::class, + App\Providers\ValidationServiceProvider::class, App\Providers\ViewComposerServiceProvider::class, /*