|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @link https://github.com/phpviet/laravel-validation |
| 4 | + * |
| 5 | + * @copyright (c) PHP Viet |
| 6 | + * @license [MIT](https://opensource.org/licenses/MIT) |
| 7 | + */ |
| 8 | + |
| 9 | +namespace PHPViet\Laravel\Validation; |
| 10 | + |
| 11 | +use PHPViet\Validation\Rules\IdVN; |
| 12 | +use PHPViet\Laravel\Validation\Rules\IpVN; |
| 13 | +use PHPViet\Laravel\Validation\Rules\MobileVN; |
| 14 | +use PHPViet\Laravel\Validation\Rules\LandLineVN; |
| 15 | +use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
| 16 | + |
| 17 | +/** |
| 18 | + * @author Vuong Minh <vuongxuongminh@gmail.com> |
| 19 | + * @since 1.0.0 |
| 20 | + */ |
| 21 | +class ServiceProvider extends BaseServiceProvider |
| 22 | +{ |
| 23 | + |
| 24 | + public function boot(): void |
| 25 | + { |
| 26 | + if (isset($this->app['validator'])) { |
| 27 | + |
| 28 | + foreach ($this->getCallableRules() as $name => $rule) { |
| 29 | + $this->app['validator']->extend($name, $rule, $rule->message()); |
| 30 | + } |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + protected function getCallableRules(): array |
| 35 | + { |
| 36 | + return [ |
| 37 | + 'land_line_vn' => new LandLineVN(), |
| 38 | + 'mobile_vn' => new MobileVN(), |
| 39 | + 'id_vn' => new IdVN(), |
| 40 | + 'ip_vn' => new IpVN(), |
| 41 | + 'ipv4_vn' => new IpVN(IpVN::IPV4), |
| 42 | + 'ipv6_vn' => new IpVN(IpVN::IPV6), |
| 43 | + ]; |
| 44 | + } |
| 45 | +} |
0 commit comments