-1

could someone show me how to get the :other or :after_field to display in the error message.

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

validation rule:

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


protected function validateAfterField($attribute, $value, $parameters)
{
    return Carbon::parse($value) > Carbon::parse($this->data[$parameters[0]]);
}
Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
ONYX
  • 5,679
  • 15
  • 83
  • 146

1 Answers1

0

I don't see much point to creating custom validation rule for this.

You can change those rules this way:

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;
}
Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291