-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
Eloquent Builder doesn't allow Mixins #28262
Comments
Heya, thanks for submitting this. This seems like a feature request or an improvement. It's best to post these at the laravel/ideas repository to get support for your idea. After that you may send a PR to the framework. Please only use this issue tracker to report bugs and issues with the framework. Thanks! |
I was under the impression that the |
You could always do something like this: Builder::macro('mixin', function ($mixin) {
$methods = (new ReflectionClass($mixin))->getMethods(
ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED
);
foreach ($methods as $method) {
$method->setAccessible(true);
Builder::macro($method->name, $method->invoke($mixin));
}
});
Builder::mixin(New YourMixins); |
Thank you! This will work until this bug gets fixed. |
Any update on this? or any reason that why eloquent\builder doesn't support |
I have the opposite problem, mixins applied to eloquent models are being forwarded to Illuminate\Database\Query\Builder. |
Description:
Eloquent Builder allows macros but doesn't allow mixins:
Steps To Reproduce:
Try adding a mixin within a service provider:
\Illuminate\Database\Eloquent\Builder::mixin(new \App\Mixins\SearchRelationship);
The text was updated successfully, but these errors were encountered: