Reputation: 7535
Lets say I have a MessageThread which has many Messages. And each Message is associated with one User.
How would i get all MessageThread objects containing at least one Message that is associated with a particular User?
Upvotes: 2
Views: 37
Reputation: 219938
Use two whereHas
constraints:
$threads = MessageThread::whereHas('messages', function ($query) {
$query->whereHas('user', function ($query) {
$query->where('user_id', 1);
});
})->get();
Upvotes: 1