2016-03-12 96 views
-1

有人可以告訴我如何讓錯誤消息中顯示: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]]); 
} 

回答

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; 
}