I have a StartDate field and a EndDate field. Both may start today or in the future. It is possible to have them both start on the same day, including today. I have to make a validation for these. What I've done so far is this:
'StartDate'=>'required|date_format:Y/m/d|after:yesterday',
'EndDate' => 'date_format:Y/m/d|after:yesterday',
What I don't know how to do is to validate true if both dates are equal as a second condition.
Anyone can help me, please ?
How to validate date format in Laravel? If a user must provide a date in a specific format then you can validate it using the date_format validator. This validator supports all formats supported by PHP's DateTime class createFromFormat() method.
Just create a new validation rule in laravel to validate the timestamp... Validator::extend('isTimeStamp', function($attribute, $value, $parameters) { return ((string) (int) $value === $value) && ($value <= PHP_INT_MAX) && ($value >= ~PHP_INT_MAX); }); You can now use isTimeStamp validation rule to validate timestamp.
You should add all your validation logic in the passes() function. It should return true or false based on the logic you have written in the function. The message() function returns a string that specifies the error message to be displayed in case the validation fails.
The validate method accepts an incoming HTTP request and a set of validation rules. If the validation rules pass, your code will keep executing normally; however, if validation fails, an exception will be thrown and the proper error response will automatically be sent back to the user.
This is how you can validate date:
'start_date' => 'required|date',
'end_date' => 'required|date|after_or_equal:start_date'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With