laravel-自定义验证
1.创建规则对象
php artisan make:rule IdCard
2.编写验证规则
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
class IdCard implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
return $this->validation_filter_id_card($value);
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return '证件号格式有误';
}
3.验证器中使用
'id_card' => ['required', new IdCard()],