Skip to content

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

Open
JoshSalway wants to merge 2 commits into12.xfrom
fix/accessor-attribute-name
Open

[12.x] Fix inconsistent accessor attribute name conversion#11
JoshSalway wants to merge 2 commits into12.xfrom
fix/accessor-attribute-name

Conversation

@JoshSalway
Copy link
Owner

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 laravel#54570

🤖 Generated with Claude Code

JoshSalway and others added 2 commits March 19, 2026 05:18
…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>
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.

1 participant