php - Category with product by vendor - laravel

one text

Solution:

WhereHas() check if it has it, but does not filter the result. Does it have a product with this store, if yes return all categories where you now includes products that does not filter.

There is an array syntax, for filtering with() call. This will show the products correctly.

Categories::with(['products' => function ($query) use ($id) {
    $query->where('store_id' ,$id);
}])

Source