I have a function where I am passing the category id and based on that I want to fetch all the products .
Here is a structure of my db
Category db:
category_name
Product db:
product_name;
category_product:
category_id;
product_id;
Below are the relations between them
In Product :
public function categories()
{
return $this->belongsToMany(Category::class);
}
In Category:
public function products()
{
return $this->belongsToMany(Product::class);
}
I have tested multiple queries but nothing worked for my case .