Skip to content

Commit 2046c27

Browse files
committed
close #108 Enhancement: Added currency_code request rule..
1 parent 6cc8abb commit 2046c27

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/Provider.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Support\Facades\Blade;
66
use Illuminate\Support\ServiceProvider;
77
use Illuminate\View\Compilers\BladeCompiler;
8+
use Illuminate\Support\Facades\Validator;
89

910
class Provider extends ServiceProvider
1011
{
@@ -28,10 +29,32 @@ public function boot(): void
2829

2930
Currency::setCurrencies($currencies ?? []);
3031

32+
$this->registerValidationRules();
3133
$this->registerBladeDirectives();
3234
$this->registerBladeComponents();
3335
}
3436

37+
public function registerValidationRules(): void
38+
{
39+
$currency_code = null;
40+
41+
Validator::extend('currency_code', function ($attribute, $value, $parameters, $validator) use(&$currency_code) {
42+
$status = false;
43+
44+
$currency_code = $value;
45+
46+
$currencies = config('money.currencies');
47+
48+
if (array_key_exists($value, $currencies)) {
49+
$status = true;
50+
}
51+
52+
return $status;
53+
},
54+
trans('validation.custom.invalid_currency', ['attribute' => $currency_code])
55+
);
56+
}
57+
3558
public function registerBladeDirectives(): void
3659
{
3760
$this->callAfterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) {

0 commit comments

Comments
 (0)