Support the ongoing development of Laravel.io →
Eloquent Laravel
Last updated 2 years ago.

vanny2000 liked this thread

1

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

1
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.

0

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

1

Thank you so much.

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

0

I created the pull request: https://github.com/laravel/framework/pull/44189

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

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.