Skip to content

[12.x] Fix inconsistent accessor attribute name conversion#59325

Draft
JoshSalway wants to merge 2 commits intolaravel:13.xfrom
JoshSalway:fix/accessor-attribute-name
Draft

[12.x] Fix inconsistent accessor attribute name conversion#59325
JoshSalway wants to merge 2 commits intolaravel:13.xfrom
JoshSalway:fix/accessor-attribute-name

Conversation

@JoshSalway
Copy link
Contributor

Summary

  • Fixes inconsistent behavior when accessing Attribute-style accessors via alternate snake_case forms (e.g., foo_1_bar vs foo1_bar)
  • Both forms correctly resolve to the same foo1Bar() method when getting values, but append('foo_1_bar')->toArray() would fail because the mutator cache only stored the canonical form foo1_bar
  • Normalizes cache keys by round-tripping through camel->snake conversion so that alternate forms resolve to the same entry

Test plan

  • All 216 existing Eloquent model tests pass
  • New test verifies both foo1_bar and foo_1_bar work with append() and toArray()

Fixes #54570

🤖 Generated with Claude Code

@github-actions
Copy link

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

JoshSalway and others added 2 commits March 23, 2026 09:47
…ution

When using the Attribute syntax (e.g. foo1Bar(): Attribute), multiple
snake_case forms like "foo_1_bar" and "foo1_bar" both map to the same
camelCase method "foo1Bar". However, only "foo1_bar" was stored in the
mutator cache (from Str::snake('foo1Bar')).

This caused append('foo_1_bar')->toArray() to fail with "Call to
undefined method getFoo1BarAttribute()" because the cache lookup for
"foo_1_bar" missed, and it fell through to the legacy accessor path.

The fix normalizes cache keys by round-tripping through camel->snake
conversion, ensuring that alternate snake_case forms resolve to the
same cache entry.

Fixes laravel#54570

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…gments

Verifies that both "foo1_bar" and "foo_1_bar" forms correctly resolve
to the same Attribute accessor when used with append() and toArray().

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JoshSalway JoshSalway force-pushed the fix/accessor-attribute-name branch from 62d683f to 5e69019 Compare March 22, 2026 23:47
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.

Inconsistent accessor attribute name conversion

1 participant