```php $query->where('category_id', $categoryId) ->whereExists(function ($q) { $q->where('target_id', $id) }); ```