3

I want to compare start_date with end_date , and end_date should be equal or greater then start_date, i am using after_or_equal validation.

return Validator::make($data, [
      'start_date' => 'required',
      'end_date' => 'required|date_format:Y-m-d|after_or_equal:start_date'
]);


after_or_create validation of laravel5.2 return error like this.
Method [validateAfterOrEqual] does not exist.
Rajeev Varshney
  • 933
  • 2
  • 13
  • 26

3 Answers3

0

you need to upgrade your version to 5.4 to use after_or_equal

https://laravel.com/docs/5.4/validation#rule-after-or-equal

Note : after_or_equal is available from version laravel 5.3

JYoThI
  • 11,977
  • 1
  • 11
  • 26
0

Validator::extend('before_equal', function($attribute, $value, $parameters, $validator) { return strtotime($validator->getData()[$parameters[0]]) >= strtotime($value); }); Or alternative is upgrade to 5.3

0

Simply send your date back by 1 day and use the after: rule!

$yesterday = date('Y-m-d', strtotime('-1 days');

$rule = ['start_date' => 'required|after:'.$yesterday];

This will work for all versions of laravel as long as the after: or before: rules are there.

lewiscool
  • 71
  • 1
  • 3