Skip to content

Commit f9a04a8

Browse files
committed
Update LaravelValidateServiceProvider.php
1 parent 459ab2e commit f9a04a8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/LaravelValidateServiceProvider.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Milwad\LaravelValidate;
44

55
use Illuminate\Support\Facades\File;
6+
use Illuminate\Support\Facades\Validator;
67
use Illuminate\Support\ServiceProvider;
78
use Milwad\LaravelValidate\Utils\CountryPhoneCallback;
89

@@ -58,5 +59,21 @@ public function boot(): void
5859
foreach ($countries as $code => $country) {
5960
CountryPhoneCallback::addValidator($code, $country);
6061
}
62+
63+
// Register rules in container
64+
if (config('laravel-validate.using_container', false)) {
65+
$rules = File::files(__DIR__.'/Rules');
66+
67+
foreach ($rules as $rule) {
68+
$className = 'Milwad\\LaravelValidate\\Rules\\' . $rule->getBasename('.php');
69+
70+
Validator::extend(
71+
$rule->getFilenameWithoutExtension(),
72+
function ($attribute, $value, $parameters, $validator) use ($className) {
73+
return (new $className($parameters))->passes($attribute, $value);
74+
}
75+
);
76+
}
77+
}
6178
}
6279
}

0 commit comments

Comments
 (0)