fix: getCasts() to include casts() method for non-incrementing models#336
Merged
albertcht merged 1 commit intohypervel:mainfrom Jan 5, 2026
Merged
Conversation
The getCasts() method was only calling $this->casts() for incrementing models. For non-incrementing models (those using HasUuids or HasUlids), only the $casts property was returned, ignoring the casts() method entirely. This caused casts defined via the casts() method to be ignored for UUID/ULID models, leading to issues like arrays not being JSON-encoded when saved.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
getCasts()method inHasAttributeswas only calling$this->casts()for incrementing models. For non-incrementing models (those usingHasUuidsorHasUlids), only the$castsproperty was returned, ignoring thecasts()method entirely.The Bug
Impact
Any model using
HasUuidsorHasUlidsthat defines casts via thecasts()method (Laravel's modern approach) would have those casts ignored. This causes issues like:The Fix
Now the non-incrementing branch also merges both the property and method, matching the behavior of the incrementing branch.
Test Plan
HasAttributesTestwith 3 test cases:testGetCastsIncludesCastsMethodForIncrementingModels- existing behavior workstestGetCastsIncludesCastsMethodForNonIncrementingModels- UUID models get casts() methodtestGetCastsMergesPropertyAndMethodForNonIncrementingModels- both property and method are merged