fixed #402
This commit is contained in:
parent
19dc25d84f
commit
6f2c936a73
@ -2,36 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Http\Requests;
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
use App\Models\Setting\Currency;
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
use Illuminate\Validation\Factory as ValidationFactory;
|
|
||||||
|
|
||||||
class Request extends FormRequest
|
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.
|
* Set the company id to the request.
|
||||||
*
|
*
|
||||||
|
46
app/Providers/ValidationServiceProvider.php
Normal file
46
app/Providers/ValidationServiceProvider.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Models\Setting\Currency;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Validator;
|
||||||
|
|
||||||
|
class ValidationServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Bootstrap any application services.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
$currency_code = null;
|
||||||
|
|
||||||
|
Validator::extend('currency', function ($attribute, $value, $parameters, $validator) use(&$currency_code) {
|
||||||
|
$status = false;
|
||||||
|
|
||||||
|
$currencies = Currency::enabled()->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()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
@ -178,6 +178,7 @@ return [
|
|||||||
App\Providers\FormServiceProvider::class,
|
App\Providers\FormServiceProvider::class,
|
||||||
App\Providers\ObserverServiceProvider::class,
|
App\Providers\ObserverServiceProvider::class,
|
||||||
App\Providers\RouteServiceProvider::class,
|
App\Providers\RouteServiceProvider::class,
|
||||||
|
App\Providers\ValidationServiceProvider::class,
|
||||||
App\Providers\ViewComposerServiceProvider::class,
|
App\Providers\ViewComposerServiceProvider::class,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user