Replies: 1 comment
-
|
As you can see, it is enough to check first parent not all parents. class_parents should be replaced with get_parent_class if (\is_string($parent = \get_parent_class(static::class)) && \method_exists($parent, '__callStatic')) {
/** @phpstan-ignore class.noParent, staticMethod.notFound */
return $parent::__callStatic($method, $parameters);
}
} if (\is_string($parent = \get_parent_class(static::class)) && \method_exists($parent, '__call')) {
/** @phpstan-ignore class.noParent, staticMethod.notFound */
return parent::__call($method, $parameters);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
-
Laravel Version
10.x to master
PHP Version
8.x
Database Driver & Version
No response
Description
Hello,
The
Macroabletrait does not work if used in a class that also uses__callor__callStaticmagic methods.That's because when either
__callor__callStaticis called it assumes that it is because of a registeredmacro. If not found it will throw an error instead of passing the call upstream in (e.g.)parent::_call[Static].I created a very small project to demonstrate this problem at https://github.com/rsd/macroable-test.
This problem affects, but is not limited to
Eloquent Models.One could argue that
resolveRelationUsing()could be used. However,resolveRelationUsing()does not take any arguments. If your method needs one or more argumentsmacro()is the only way.Keeping with the
Eloquentscenario, one reason to want to use this way instead of having it all in theModelis to be able to break optional dependable Models into different Laravel Modules or packages.For example:
Studentsmodel has all general information for students in a College.Different Colleges could need other models to expand
Studentsinformation depending on the majors it offers, likeEngineer,Physics,Arts.So, different Colleges would install the modules / packages it needs.
Otherwise, it would need all relationships to be hardcoded into the
StudentsModel breaking modularity.I have already created PRs for:
Note that the solution is barely 3 lines per method.
Steps To Reproduce
1 - Create a Model like:
2 - Register a
macro()at a ServiceProvider like:Call it like:
Macroable will throw an exception for
createorhydrate.Beta Was this translation helpful? Give feedback.
All reactions