dwightwatson / validating

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

Add support for Laravel 7.0 #221

Closed dwightwatson closed 4 years ago

dwightwatson commented 4 years ago

This adds support for Laravel 7.0.

Closes #220.

Mechstud commented 4 years ago

Hi, there seems to be an issue with Laravel 7.x providing custom Casts feature: https://laravel.com/docs/7.x/eloquent-mutators#custom-casts

I defined a custom Cast, for eg: ZoneEnum, which implements CastsAttributes interface. Eg: North, South, East and West And in the get() method of this, I return an object of ZoneEnum, based on the value stored in the database. While setting the attribute, I mutate from a ZoneEnum object to its string value, in the set() method implementation.

The problem here is that in the getModelAttributes() function (refer: https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php#L131), you are getting attribute values utilizing the Accessor logic. This makes Laravel's code cast the (already mutated/set) value back to ZoneEnum object. This then fails the validation logic.

Also, I noticed that getAttributes() function alone should be enough; you dont really need to mutate again using getAttributeValue(), unless I am missing something ?