dwightwatson / validating

Automatically validating Eloquent models for Laravel
MIT License
968 stars 76 forks source link

add custom format check to date checking #237

Closed spencerrlongg closed 1 year ago

spencerrlongg commented 1 year ago

Thanks so much for this package, we use it pretty extensively and are glad it exists.

This is just a small PR to account for custom_date validation.

When using a custom date cast like date:Y-m-d custom date validation custom_date:Y-m-d fails because the default returned is Y-m-d H:i:s. In Laravel 8 a new conern was added: isDateCastableWithCustomFormat() - adding this to the getModelAttributes() date check resolves the issue and I haven't been able to find any side effects.

Let me know if you have any questions and again thanks for the package.

dwightwatson commented 1 year ago

Happy to bring this in - would you mind adding tests to confirm the behaviour?

spencerrlongg commented 1 year ago

Sure thing! added to the PR. Quick explanation of what I did here:

I removed the method at the bottom as that seemed to allow any kind of date or datetime to pass no matter what.

What I'm left with is tests that pass with the new check: image

And fail without the new check: image

dwightwatson commented 1 year ago

Beautiful - thanks for considering all those options. I'll tag a new release shortly.