错误消息输出无法正确显示

时间:2016-03-12 02:55:17

标签: laravel laravel-5 laravel-5.2 laravel-validation

有人可以告诉我如何获取:other或:after_field以显示在错误消息中。

$messages = ["after_field" => "The :attribute must be greater than the :other."];

验证规则:

$rules = ['sale_end' => 'date|after_field:sale_start']


protected function validateAfterField($attribute, $value, $parameters)
{
    return Carbon::parse($value) > Carbon::parse($this->data[$parameters[0]]);
}

1 个答案:

答案 0 :(得分:0)

我认为没有为此创建自定义验证规则。

您可以通过这种方式更改这些规则:

public function rules() 
{ 
    $date = $this->data[$parameters[0]];
    // here you need to change $date format to be valid according to http://php.net/manual/en/datetime.formats.php
    $rules = ['sale_end' => 'date|after:'.$date];
    // ...
   return $rules;
}