Skip to content

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

Merged
taylorotwell merged 4 commits into
laravel:9.xfrom
mikeydevelops:eloquent-higher-order-proxy-properties
Mar 12, 2022
Merged

[9.x] Extend eloquent higher order proxy properties#41449
taylorotwell merged 4 commits into
laravel:9.xfrom
mikeydevelops:eloquent-higher-order-proxy-properties

Conversation

@mikeydevelops

Copy link
Copy Markdown
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.

2 participants