php – Laravel验证:检查验证器失败的原因

前端之家收集整理的这篇文章主要介绍了php – Laravel验证:检查验证器失败的原因前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如果有办法检查验证器是否由于唯一规则而特别失败?
$rules = array(
            'email_address' => 'required|email|unique:users,email','postal_code' => 'required|alpha_num',);

        $messages = array(
            'required' => 'The :attribute field is required','email' => 'The :attribute field is required','alpha_num' => 'The :attribute field must only be letters and numbers (no spaces)'
        );

        $validator = Validator::make(Input::all(),$rules,$messages);

        if ($validator->fails()) {

在外行人看来,我基本上想知道:“验证失败了,因为email_address不是唯一的吗?”

检查返回的失败规则数组中的特定规则
if ($validator->fails()) {

    $FailedRules = $validator->Failed();

    if(isset($FailedRules['email_address']['Unique'])) {

    ...
原文链接:https://www.f2er.com/laravel/133632.html

猜你在找的Laravel相关文章