[11.x] Handle aliases when appending attribute accessor #54589
Closed
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.
Closes #54570
TLDR:
getFooBarQuzAttribute
way, appending with any alias works when casting to arrayreturn Attribute::make
it causes an exception for some aliases that work with the above wayWhy
Currently if you use the new style attribute accessor in a method, such as:
As we know, we can access it via the model with various aliases, such as :
Appending works if you use the full snake of the method:
However some aliases do not work, when using the this way of defining a attribute, which do work when you use the alternative way ie
getFooBarBazAttribute()
:Where as if you used the alternative
get
notation:It works with all aliases:
What it fixes
This PR fixes it so all the aliases work, regardless of how you're using the accessor - ie
getXAttribute
or the class, which is what I would expect. Currently it does not work if you use the class way of doing it.with fixes examples below:
In a real world situation, it just means you can append the attribute with whatever alias you prefer, keeping it consistent with how you're accessing it from the model, which is a win win? And if you're switching from the
get
notation to the class way, it will continue to work.Doesn't break anything from my understanding, and just resolves this particular issue with aliasing, which already works via the other way ie
getFooBarBazAttribute()
🕺🏻Hopefully tests are OK, but any issues let me know 🫡