0

It appear there is no validation rule in Laravel that start_date and end_date can not be the same.

How do I overcome this?

2

1 Answer 1

1

Try this one in controller/model where you defined rules to check, and get the proper validation you want

Validator::extend('before_equal', function($attribute, $value, $parameters) {
    return strtotime(Input::get($parameters[0])) >= strtotime($value);
});

$rules = array(
    'start'=>'required|date|before_equal:stop',
    'stop'=>'required|date',
);
Sign up to request clarification or add additional context in comments.

6 Comments

this will compare dates by its string value, with help of strtotime
I am assuming stop is end_date ?
yes right :) start = start_date and stop = end_date
Thank you, how do I add custom validation error message for before_equal error?
by adding this validation rule to validation.php file for common use
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.