Support the ongoing development of →
Eloquent Laravel
Last updated 1 year ago.

vanny2000 liked this thread


Hey, I'm not entirely sure if that's the intended behavior or not, but I found a way to get the results you want

$users = User::query()
   ->withWhereHas('comments', function ($query) {

Also, next time make sure to add all relevant files, (models, migration, factories) it took me some time to set up the environment with just the information you provided.

siarheipashkevich liked this reply

Solution selected by @driesvints

@cosmeoes thanks for the response and your solution.

By the documentation we can specify nested relations like comments.commentable for with or has methods it's not relevant for withWhereHas?

And your solution like a workaround as for me.


I think it makes sense that it would work the way you expected it to work. I was going to check it and create a pull request if I thought it was a mistake but I'm a little busy right now, maybe in the future.

siarheipashkevich liked this reply


Thank you so much.

I'll wait your pull request and mark this thread as resolved after that.


I created the pull request:

We'll see what the Laravel team thinks about it.


Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.