├── CHANGELOG.md ├── resources └── lang │ ├── en │ └── validation.php │ └── vi │ └── validation.php ├── src ├── Rules │ ├── IdVN.php │ ├── MobileVN.php │ ├── LandLineVN.php │ ├── CallableRule.php │ └── IpVN.php └── ServiceProvider.php ├── LICENSE.md ├── composer.json └── README.md /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | Tất cả lịch sử tiến trình phát triển thư viện 4 | 5 | # 1.0.5 6 | 7 | - Hổ trợ Laravel 6 & 7. 8 | 9 | # 1.0.4 10 | 11 | - Sửa lỗi DI khi khởi tạo ip rules. 12 | 13 | # 1.0.3 14 | 15 | - Sửa lỗi lazy load service provider đè lên thư viện. 16 | 17 | # 1.0.2 18 | 19 | - Cải thiện performance thông qua lazy load service provider. 20 | 21 | # 1.0.1 22 | 23 | - Hổ trợ đa ngôn ngữ mặc định. 24 | -------------------------------------------------------------------------------- /resources/lang/en/validation.php: -------------------------------------------------------------------------------- 1 | ':attribute must be an id number of Vietnam.', 11 | 'mobile' => ':attribute must be a mobile phone number of Vietnam.', 12 | 'land_line' => ':attribute must be a land line phone number of Vietnam.', 13 | 'ip' => [ 14 | 'v4' => ':attribute must be Vietnam ipv4.', 15 | 'v6' => ':attribute must be Vietnam ipv6.', 16 | 'default' => ':attribute must be Vietnam ip.', 17 | ], 18 | ]; 19 | -------------------------------------------------------------------------------- /resources/lang/vi/validation.php: -------------------------------------------------------------------------------- 1 | ':attribute phải là số chứng minh thư hoặc thẻ căn cước tại Việt Nam.', 11 | 'mobile' => ':attribute phải là số di động tại Việt Nam.', 12 | 'land_line' => ':attribute phải là số điện thoại bàn tại Việt Nam.', 13 | 'ip' => [ 14 | 'v4' => ':attribute phải là ipv4 tại Việt Nam.', 15 | 'v6' => ':attribute phải là ipv6 tại Việt Nam.', 16 | 'default' => ':attribute phải là ip Việt Nam.', 17 | ], 18 | ]; 19 | -------------------------------------------------------------------------------- /src/Rules/IdVN.php: -------------------------------------------------------------------------------- 1 | 15 | * @since 1.0.0 16 | */ 17 | class IdVN extends CallableRule 18 | { 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function passes($attribute, $value): bool 23 | { 24 | return Validator::idVN()->validate($value); 25 | } 26 | 27 | /** 28 | * {@inheritdoc} 29 | */ 30 | public function message(): string 31 | { 32 | return __('phpVietValidation::validation.id'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Rules/MobileVN.php: -------------------------------------------------------------------------------- 1 | 15 | * @since 1.0.0 16 | */ 17 | class MobileVN extends CallableRule 18 | { 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function passes($attribute, $value): bool 23 | { 24 | return Validator::mobileVN()->validate($value); 25 | } 26 | 27 | /** 28 | * {@inheritdoc} 29 | */ 30 | public function message(): string 31 | { 32 | return __('phpVietValidation::validation.mobile'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Rules/LandLineVN.php: -------------------------------------------------------------------------------- 1 | 15 | * @since 1.0.0 16 | */ 17 | class LandLineVN extends CallableRule 18 | { 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function passes($attribute, $value): bool 23 | { 24 | return Validator::landLineVN()->validate($value); 25 | } 26 | 27 | /** 28 | * {@inheritdoc} 29 | */ 30 | public function message(): string 31 | { 32 | return __('phpVietValidation::validation.land_line'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Rules/CallableRule.php: -------------------------------------------------------------------------------- 1 | 15 | * @since 1.0.0 16 | */ 17 | abstract class CallableRule implements Rule 18 | { 19 | /** 20 | * Hổ trợ sử dụng rule dưới dạng extension. 21 | * 22 | * @param $attribute 23 | * @param $value 24 | * @param $parameters 25 | * @param $validator 26 | * @return bool 27 | */ 28 | public function __invoke($attribute, $value, $parameters, $validator) 29 | { 30 | return $this->passes($attribute, $value); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) PHP Viet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "phpviet/laravel-validation", 3 | "description": "Laravel validation hổ trợ kiểm tra dữ liệu đặc thù trong nước", 4 | "keywords": [ 5 | "phpviet", 6 | "laravel-validation" 7 | ], 8 | "homepage": "https://github.com/phpviet/laravel-validation", 9 | "license": "MIT", 10 | "authors": [ 11 | { 12 | "name": "Vuong Xuong Minh", 13 | "email": "vuongxuongminh@gmail.com" 14 | } 15 | ], 16 | "require": { 17 | "php": "^7.1", 18 | "phpviet/validation": "^1.0", 19 | "illuminate/support": "^5.7 || ^6.0 || ^7.0" 20 | }, 21 | "require-dev": { 22 | "orchestra/testbench": "^3.7 || ^4.0 || ^5.0" 23 | }, 24 | "autoload": { 25 | "psr-4": { 26 | "PHPViet\\Laravel\\Validation\\": "src" 27 | } 28 | }, 29 | "autoload-dev": { 30 | "psr-4": { 31 | "PHPViet\\Laravel\\Validation\\Tests\\": "tests" 32 | } 33 | }, 34 | "config": { 35 | "sort-packages": true 36 | }, 37 | "extra": { 38 | "branch-alias": { 39 | "dev-master": "1.0-dev" 40 | }, 41 | "laravel": { 42 | "providers": [ 43 | "PHPViet\\Laravel\\Validation\\ServiceProvider" 44 | ] 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Rules/IpVN.php: -------------------------------------------------------------------------------- 1 | 16 | * @since 1.0.0 17 | */ 18 | class IpVN extends CallableRule 19 | { 20 | const IPV4 = BaseIpVN::IPV4; 21 | 22 | const IPV6 = BaseIpVN::IPV6; 23 | 24 | /** 25 | * @var int|null 26 | */ 27 | protected $version; 28 | 29 | /** 30 | * IpVN constructor. 31 | * 32 | * @param int|null $version 33 | */ 34 | public function __construct(?int $version = null) 35 | { 36 | $this->version = $version; 37 | } 38 | 39 | /** 40 | * {@inheritdoc} 41 | */ 42 | public function passes($attribute, $value): bool 43 | { 44 | return Validator::ipVN($this->version)->validate($value); 45 | } 46 | 47 | /** 48 | * {@inheritdoc} 49 | */ 50 | public function message(): string 51 | { 52 | switch ($this->version) { 53 | case self::IPV4: 54 | 55 | return __('phpVietValidation::validation.ip.v4'); 56 | case self::IPV6: 57 | 58 | return __('phpVietValidation::validation.ip.v6'); 59 | default: 60 | 61 | return __('phpVietValidation::validation.ip.default'); 62 | 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/ServiceProvider.php: -------------------------------------------------------------------------------- 1 | 19 | * @since 1.0.0 20 | */ 21 | class ServiceProvider extends BaseServiceProvider 22 | { 23 | public function boot(): void 24 | { 25 | $this->loadTrans(); 26 | $this->loadExt(); 27 | } 28 | 29 | protected function loadTrans(): void 30 | { 31 | $this->publishes([ 32 | __DIR__.'/../resources/lang' => resource_path('lang/vendor/phpVietValidation'), 33 | ]); 34 | $this->loadTranslationsFrom(__DIR__.'/../resources/lang/', 'phpVietValidation'); 35 | } 36 | 37 | protected function loadExt(): void 38 | { 39 | if (isset($this->app['validator'])) { 40 | foreach ($this->getCallableRules() as $name => $rule) { 41 | $this->app['validator']->extend($name, $rule, $rule->message()); 42 | } 43 | } 44 | } 45 | 46 | protected function getCallableRules(): array 47 | { 48 | return [ 49 | 'land_line_vn' => $this->app->make(LandLineVN::class), 50 | 'mobile_vn' => $this->app->make(MobileVN::class), 51 | 'id_vn' => $this->app->make(IdVN::class), 52 | 'ip_vn' => $this->app->make(IpVN::class), 53 | 'ipv4_vn' => $this->app->make(IpVN::class, ['version' => IpVN::IPV4]), 54 | 'ipv6_vn' => $this->app->make(IpVN::class, ['version' => IpVN::IPV6]), 55 | ]; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |