在Laravel刀片中访问const值时出现问题

时间:2017-08-06 23:44:14

标签: laravel laravel-5.3 laravel-5.4

"Min_UserName" =>  "Min :chars chars for username",

JQuery的

$("form#registerForm").validate({
    rules: {
        UserName: {
            required: true,
            minlength: 6
        }
    },
    messages: {
        UserName: {
            required:  "{!! trans('Register.Required_UserName') !!}",
            minlength: "{!! trans('Register.Min_UserName', 
                                      ['chars' => '\App\UserMinValue::Min_UserName']) !!}"
        }
    }
});

namespace App\Architecture\MinMaxValues;

class UserMinValue {
    const Min_UserName = 6;
}

当前输出

minlength:  "Min App\UserMinValue::Min_UserName chars for username",

预期输出

minlength:  "Min 6 chars for username",

我错过了什么吗?

1 个答案:

答案 0 :(得分:1)

您在类路径周围有引号,因此发出字符串路径而不是您需要的值,更改:

['chars' => '\App\UserMinValue::Min_UserName']

要:

['chars' => \App\UserMinValue::Min_UserName]