Goal:
On my product's detail page I want to display a breadcrumb of all the parent categories that my product has.
For example, if there is a product that is assigned a category_id pointing to a SubSubCategory; I want the breadcrumb to be:
Root Category / SubCategory / SubSubCategory
Problem:
Some products might a category_id that points to the root category (has no children) and other products might have a category_id that points to a category that is 2 levels deep (has two parents). How do I handle these scenarios?
What I have tried:
This is my https://i.stack.imgur.com/anCRh.png
This is my https://i.stack.imgur.com/g1iHS.png
So far, if I wanted to get the category breadcrumb of a specific product I would do it like this:
{{$product->category->parent->name}} / {{$product->category->name}}
But it quickly had errors with the products that had a root category assigned to them. Because I was trying to get a relationship that didn't exist.