@sharim because you checks just tag existance, not that tags associated with the given product
Assuming you have defined mainCategory and subCategory relationships on product
public function show($parentSlug, $childSlug, $slug)
{
$product = Product::where('slug', $slug)
->where('ecommerce', true)
->whereHas('mainCategory', fn ($query) => $query->where('slug', $parentSlug)) // here
->whereHas('subCategory', fn ($query) => $query->where('slug', $childSlug)) // and here
->firstOrFail();
// ...
}