Back

Hey Laravel Developers

When working with web applications, one of the common validations we deal with involves dates.

Many times, I’ve seen developers use the date validation rule to validate date input fields.

However, I’d urge you to use the date_format validation rule instead.

The reason is that the date_format rule gives clients a clear understanding of the format the API expects for the input.

For example, a client might mistakenly pass a datetime in the request, expecting the timestamps to be stored, but you only store the date in the backend.

What do you think about this? Any opinions? I’d love to discuss it!

image

1

51

  • No matching results...
  • Searching...

/ 1000

Depends on the use case. API, yes absolutely validate on the format - but also make sure your docs specify the format that you expect. A front end application with a UI should already handle that for the user by giving them a date picker or datetime picker so that there's no guessing involved.

89