Skip to content
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

[9.x] Extend eloquent higher order proxy properties #41449

Merged

Conversation

mikeydevelops
Copy link
Contributor

Hello,

Pull requests #41096 and #41296 added the ability to negate query conditions, primarily negating closures of conditions or in other words: scopes.

I remembered there was a nice way of changing the boolean of model scopes from and to or using the HigherOrderBuilderProxy.
I decided to add an easy way to add proxied properties and for starters in addition to the orWhere method I also added the methods whereNot and orWhereNot to be proxied.

I have also added tests.

This is what is changed in terms of coding and syntactic sugar.

Before you would write:

Model::query()->whereNot(function (Builder $query) {
    $query->someScope();
});

Model::query()->orWhereNot(function (Builder $query) {
    $query->someOtherScope();
});

Now you can use:

Model::query()->whereNot->someScope();

Model::query()->orWhereNot->someOtherScope();

I think this is quite nice looking code.

@mikeydevelops mikeydevelops changed the title [9.x] Extend eloquent higher order proxy properties with new [9.x] Extend eloquent higher order proxy properties Mar 12, 2022
@taylorotwell taylorotwell merged commit 0a503ed into laravel:9.x Mar 12, 2022
@mikeydevelops mikeydevelops deleted the eloquent-higher-order-proxy-properties branch March 12, 2022 17:22
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.

None yet

2 participants