Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[12.x] feat: Make custom eloquent castings comparable for more granular isDirty check #55945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

SanderSander
Copy link
Contributor

@SanderSander SanderSander commented Jun 6, 2025

This PR adds the ability to compare custom casted attributes to detect if a model attribute is dirty or not.

Some background:
Currently when a JSON field is used in the database and a cast to object or collection is used, the format {"key": "value", "key2": "value"} and {"key":"value","key2":"value"} will match and will not be flagged as dirty.

The problem is that this isn't possible for custom casts (A good example would be spatie/laravel-data)

This PR doesn't solve the problem directly for JSON fields, but gives custom casts the possibility to give more granular control about how the values will be compared in the originalIsEquivalent method.

This is done by checking if the attribute is casted by a class and if that custom caster has the method compare

This also gives the ability to prevent dirty hits when the order of a JSON field is changed, There was a loose comparison but that was reverted in #41337

@taylorotwell taylorotwell merged commit cf9cede into laravel:12.x Jun 6, 2025
59 checks passed
AhmedAlaa4611 referenced this pull request in laravel/docs Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.