I've stumbled upon a small issue regarding @mixin
.
In my codebase, I'm have to wrap (let's call it Wrapper) an Eloquent model, which I then forward call/get/set/_isset/unset to in order for the change to be as transparent as possible.
I then inherit from Wrapper to have a wrapped version of each of my models, so I can separate database declarations (i.e. scopes, relations) from usage logic.
Each wrapper then also uses the corresponding model as a mixin in order to allow completion for properties and relations.
Problem is, for some Wrapper methods I use the same names as Model (e.g. is
and getModel
).
When I use those in my code, the extension brings up the Model version instead of the Wrapper.
An example of what I'm talking about :
If I try to understand what's going on here, I assume @mixin
merges the methods and properties tree of the specified class into the current one. The mixin class itself being a subclass of Model, it possesses the "is" method. Then when I try to use it, it goes to the closer path in the inheritance tree, which is itself from the mixin.
I don't know what's the best approach here. While I can reason through why it works that way, I think mixins are mostly used the way I described it here : as a fallback behind some kind of forward mechanism.
A solution to this problem of mine could be (I'm talking without knowing implementations details so I might be way off) to not merge the methods and properties tree when using @mixin
but treat it as a separate kind of inheritance with the lowest priority.
Such change should probably be enabled or not in the settings, as some people might prefer the current behaviour.
Regards.