-
Notifications
You must be signed in to change notification settings - Fork 919
Add support for single-method Laravel Accessors and Mutators #4164
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
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
…r return type and function visibility
[ci skip] [skip ci]
[ci skip] [skip ci]
…() to avoid reflecting twice the same method
tabacitu
requested changes
Feb 10, 2022
|
Purrfect... Thank you @pxpm . I've just changed the method name, that's all. Merging! |
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.
WHY
BEFORE - What was wrong? What was happening before this PR?
As reported in #4163 , a new feature introduced by Laravel laravel/framework#40022 allow developers to setup acessors and mutators using a different syntax. Backpack guessing abilities were broken by this change, as this functions would look similar to relation functions.
AFTER - What is happening after this PR?
You can safely use the new Laravel feature.
HOW
How did you achieve that, in technical terms?
I prepared the grounds for us to move towards requiring return types in the relation functions that developer wants Backpack to guess from. I moved all logic that deals with checking method properties to a single method to reduce the margin of error until we don't make the change I talked before.
Added a check for the function return type, since the new Laravel feature requires the developer to define the return type, we can safely exclude them from beeing relationships.
Also added a check for method visibility as relationships methods are always public.
Still not perfect until we enforce the return types, but is better than yesterday! 👍
Is it a breaking change or non-breaking change?
non-breaking
How can we test the before & after?
Try adding the new Laravel feature in Monster model for example, before it would error. After it would work 👍