packy
6 months ago

Get "Grandparent" relationship from child

Posted 6 months ago by packy

So I have been trying to figure this out for a while and I just kind find the right relationship, or am using it wrong. Basically I am trying to get the "Grandparent" relationship from the child. Right now I have 3 tables:

merchandises
-id
-product_type_id;
-name;
-description;
-slug;

product_types
-id
-shop_category_id;
-name;
-slug;

shop_categories
-id
-name;
-slug;

So on the Merchidese model I want to be able to get the shop_category slug. I thought the relationship would be

public function shopCategory()
    {
        return $this->hasOneThrough(ShopCategory::class, ProductType::class);
    }

but that assumes product_types has a merchandise_id which it doesnt.

Merchandise HasOne ProuductType that HasOne ShopCategory. So how do I get the ShopCategory from the Merchandise??

Please sign in or create an account to participate in this conversation.