Skip to content

[12.x]: Add UseEloquentBuilder attribute to register custom Eloquent Builder #56025

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

Conversation

KIKOmanasijev
Copy link
Contributor

Hello!

This pull request introduces a new attribute, #[UseEloquentBuilder], defined in Illuminate\Database\Eloquent\Attributes, to simplify the registration of custom Eloquent Query Builders for models in Laravel.

Currently, to use a custom query builder, you need to override the newEloquentBuilder method in your model, like this:

class MyModel extends Model
{
    // ...
    public function newEloquentBuilder($query)
    {
        return new CustomBuilder($query);
    }
}

With this new attribute, we can achieve the same result more elegantly:

#[UseEloquentBuilder(CustomBuilder::class)]
class MyModel extends Model
{
    // ...
}

@rodrigopedra
Copy link
Contributor

That is the only one I am missing from the new attributes helpers.

But I won't hold my air due to previous attempts: #55334, #54600, #53176

Fingers crossed!

@taylorotwell taylorotwell merged commit 11e3363 into laravel:12.x Jun 13, 2025
60 checks passed
@halikhan
Copy link

great contribution.

@pelmered
Copy link
Contributor

pelmered commented Jul 3, 2025

Finally! I have been waiting for this since #53176 was rejected. I'm very happy this got merged! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants