我在Laravel 5.0中创建了一个新的自定义验证,如下所示,以匹配确切的长度验证。我还在validation.php
// app/Validators/CustomValidator.php
<?php namespace App\Validators;
use App;
use Illuminate\Validation\Validator;
class CustomValidator extends Validator
{
public function validateExactLength($attribute, $values, $params)
{
return ($params[0] === strlen($values));
}
}
// resources/lang/en/validation.php
"exact_length" => "The :attribute must be a :exact_length characters."
它就像魅力一样,如果失败则打印消息......
“myFieldName必须是:exact_length 字符。”
请注意粗体字符号,即它不会将其替换为我在验证请求文件中提供的值
app/Http/Requests/StoreSmsPriceRequest.php
public function rules()
{
return [
'MyFieldName' => 'required|exact_length:6'
];
}
所以问题是不会在错误消息中打印所需的长度。怎么办?