Skip to content
🇨🇳Laravel idcard validator
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.editorconfig
.gitattributes
.gitignore
.php_cs
.scrutinizer.yml
.styleci.yml
.travis.yml
README.md
composer.json
phpunit.xml.dist

README.md

laravel-idcard-validator

Build Status StyleCI Latest Stable Version Latest Unstable Version Total Downloads License Scrutinizer Code Quality Code Coverage FOSSA Status

安装

$ 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],
        ];
    }
}

验证不通过时,默认返回 无效的身份证号码

License

FOSSA Status

You can’t perform that action at this time.