Eloquent Builder allows macros but doesn't allow mixins:
In ForwardsCalls.php line 50:
Call to undefined method Illuminate\Database\Eloquent\Builder::mixin()
Try adding a mixin within a service provider: \Illuminate\Database\Eloquent\Builder::mixin(new \App\Mixins\SearchRelationship);
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!
@driesvints,
I was under the impression that the Macroable trait provided the mixin functionality too. Would this not be a bug? Eloquent's Builder gets its macro ability from the base Query Builder (via ForwardsCalls), so the mixin ability should also be present.
@mikemand
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);
@Ciaro,
Thank you! This will work until this bug gets fixed.
Any update on this? or any reason that why eloquent\builder doesn't support mixins?
I have the opposite problem, mixins applied to eloquent models are being forwarded to Illuminate\Database\QueryBuilder.
Most helpful comment
Any update on this? or any reason that why eloquent\builder doesn't support
mixins?