Skip to content

Added two new "field" types: has and scope. This grants the ability t…#20

Open
HenriqueSPin wants to merge 4 commits into
williamoliveira:masterfrom
HenriqueSPin:master
Open

Added two new "field" types: has and scope. This grants the ability t…#20
HenriqueSPin wants to merge 4 commits into
williamoliveira:masterfrom
HenriqueSPin:master

Conversation

@HenriqueSPin
Copy link
Copy Markdown

@HenriqueSPin HenriqueSPin commented Jan 18, 2019

Added two new "field" types: has and scope. This grants the ability to query the eloquent model with the has() and/or to add a model scope.

Usage:

Eloquent:
Post::hotAndPopular()->get();

With arrayQuery:
Post::arrayQuery([ "scopes" => "hotAndPopular" ])->get();

You can even add N scopes like that:
Post::arrayQuery([ "scopes" => ["whatsNew", "hotAndPopular"] ])->get();

Same goes to query relationship existence:

Eloquent:
Post::has("comments")->get();

With arrayQuery:
Post::arrayQuery([ "has" => "comments" ])->get();

You can also add N relationships like that:
Post::arrayQuery([ "has" => ["comments", "author"] ])->get();

…o query the eloquent model with the has(<relationship>) and/or to add a model scope.

E.g.:

Eloquent:
Post::hotAndPopular()->get();

With arrayQuery:
Post::arrayQuery([ "scope" => "hotAndPopular" ])->get();

You can even add N scopes like that:
Post::arrayQuery([ "scope" => ["whatsNew", "hotAndPopular"] ])->get();

Same goes to query relationship existence:

Eloquent:
Post::has("comments")->get();

With arrayQuery:
Post::arrayQuery([ "has" => "comments" ])->get();

You can also add N relationships like that:
Post::arrayQuery([ "has" => ["comments", "author"] ])->get();
Comment thread src/ArrayBuilder.php Outdated
Comment thread src/ArrayBuilder.php Outdated
Comment thread src/ArrayBuilder.php Outdated
Comment thread src/ArrayBuilder.php Outdated
Comment thread src/ArrayBuilder.php Outdated
Comment thread src/ArrayBuilder.php Outdated
@HenriqueSPin
Copy link
Copy Markdown
Author

@williamoliveira Could you please provide some feedback?

@williamoliveira
Copy link
Copy Markdown
Owner

I do not work with PHP for some time I cannot test it manually right now, but the feature seems fine.
Could you just implement some automated tests? they are very easy to write in this lib.

@HenriqueSPin
Copy link
Copy Markdown
Author

@williamoliveira Sure! I'll get to it.
BTW I've tried to reach you via LinkedIn. Can you please take a look?

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.

3 participants