0
验证错误消息我很肯定我缺少的只是一些小的,但该死的地狱无法弄清楚..请帮我家伙:)Laravel 5.2定制与参数
我已经扩展AppServiceProvider .PHP
public function boot()
{
//
Validator::extend('ageLimit', 'App\Http\[email protected]');
}
我已经创造了新的CustomValidator.php
<?php
namespace App\Http;
use DateTime;
class CustomValidator {
public function validateAgeLimit($attribute, $value, $parameters, $validator)
{
$today = new DateTime(date('m/d/Y'));
$bday = new DateTime($value);
$diff = $bday->diff($today);
$first_param = $parameters[0];
if($diff->y >= $first_param){
return true;
}else{
return false;
}
}
}
我添加编新线validation.php
/*
|--------------------------------------------------------------------------
| Custom Validation Language Lines
|--------------------------------------------------------------------------
|
| Here you may specify custom validation messages for attributes using the
| convention "attribute.rule" to name the lines. This makes it quick to
| specify a specific custom language line for a given attribute rule.
|
*/
'age_limit' => ':attribute -> Age must be at least :ageLimit years old.',
'custom' => [
'attribute-name' => [
'rule-name' => 'custom-message',
],
],
这才是我的规则:
'birth_date' => 'required|date|ageLimit:15',
所有这一切工作正常...排除的参数:和ageLimit在validation.php文件..
我怎样才能达到那里参数15我在规则中传递?
因为我得到这个消息:
Birth day -> Age must be at least :ageLimit years old.
和肯定,我想获得这样的:
Birth day -> Age must be at least 15 years old.
工程就像一个魅力!!!!! +1000谢谢高手:) –