-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[8.x] Adds a simple where
helper for querying relations
#38499
[8.x] Adds a simple where
helper for querying relations
#38499
Conversation
I think this one can count as a "fixed papercut" and Taylor can take the day off 😄 |
Sorry I'm too retarded to understand. |
@DarkGhostHunter he is making a reference to this tweet from Taylor:
link to tweet: https://twitter.com/taylorotwell/status/1427286854584393740 And, since then Taylor is making a PR each day to fix small annoyances for developers (aka papercut) suggested in that thread. So, I think he means your PR is such a good improvement that Taylor can take a day off because of it. |
Thanks, I feel less dumber now. |
I purposely left out For example, I use this to get all the Post that use one single image. $image = Image::find(3)
// Before
$posts = Post::whereHas('images', function ($query) use ($image) {
$query->whereKey($image);
});
// After
$posts = Post::whereRelationHas('images', $image)->get(); I would prefer |
Amazing. Now all that's left is to put it in the documentation. |
@Geovanek feel free to send in a PR 👍 |
@DarkGhostHunter can you also do a helper for withCount withSum etc, so i don't have to write query closures 😄 |
Nice sugar here, but is it backward compatible? What if you have a column called The |
Same with ‘whereDate’ and others: use the ‘where’ method when possible.
Italo Baeza C.
… El 08-09-2021, a la(s) 05:25, Lupacescu Eduard ***@***.***> escribió:
Nice sugar here, but is it backward compatible? What if you have a column called relation in your User model?
The User::whereRelation('posts') was translated into where users.relation = 'posts' will this still be working?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@DarkGhostHunter Seems like |
@DarkGhostHunter is there any way to make it work with
|
NOPE. |
What?
This is sugar for
whereHas()
for simplewhere
clauses.How?
Basically creates the
whereRelation()
andorWhereRelation()
helpers, andwhereMorphRelation()
andorWhereMorphRelation()
for morph relations. Since these use thewhere()
method underneath, you can do advanced things:Why?
Removes code complexity by making the query more readable when dealing with simple
where
clauses over relations.Breaking Changes
None - it's merely and additive PR.