I have 3 tabes categories, sub_categories & products
- category table
---------------------
| id | category_name |
---------------------
- sub_category table
--------------------------------------------
| id | category_id(FK) | sub_category_name |
--------------------------------------------
- product table
-----------------------------------------------------------------
| id | sub_category_id(FK) | product_name | product_description |
-----------------------------------------------------------------
**How do I get product category name using hasOneThrough eloquent relationship ( or using any other relationship). I tried this in product model **
public function category(){
return $this->hasOneThrough(
Category::class,
SubCategory::class
);
}
But it gives error: Unknown column 'sub_categories.product_id'