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) {
$query->withWhereHas('commentable');
})->get();
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
@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: https://github.com/laravel/framework/pull/44189
We'll see what the Laravel team thinks about it.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community