godruoyi / laravel-idcard-validator
Laravel 身份证验证器
Installs: 5 550
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- laravel/framework: 5.* || ^6.0 || ^7.0 || ^8.0
Requires (Dev)
- laravel/framework: ^5.7 || ^7.0
- mockery/mockery: ^1.2
- orchestra/testbench: ^3.5
- phpunit/phpunit: ~7
This package is auto-updated.
Last update: 2024-12-04 14:19:28 UTC
README
安装
$ composer require godruoyi/laravel-idcard-validator -vvv
使用
Laravel 版本小于 5.5 时,需要手动在 app\config.php
添加 service provider
:
Godruoyi\LaravelIdCard\ServiceProvider::class,
通过 Validator 面门使用:
Validator::make([ 'idcard' => '110101199801012385', ], [ 'idcard' => 'required|string|idcard', ]);
通过 FormRequest 使用:
class UserRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ 'idcard' => 'required|idcard', // 或者 'idcard' => ['required', new \Godruoyi\LaravelIdCard\Rule], ]; } }
验证不通过时,默认返回 无效的身份证号码
。