$dogs = Dog::whereHas('owners', function($q) use($ownerIds) { $q->whereIn('id', $ownerIds); })->get();