Feb 13, 2018
6
Level 1
How i can get data from multiple models
Hi,
i have 4 models
Products field id, name
Categories field id, name
CategoryProducts field id, product_id, category_id
CleanURL field id, product_id, category_id, clean_url
I want to fetch all products belong to specific category id and also want to fetch url of those product that belongs to specified category
i have created this method into Category model
public function Products()
{
return $this->belongsToMany('App\Product', 'category_products', 'category_id', 'product_id');
}
it gives me all product info related to requested category by this call in category controller
$allproductData = Category::find($alldata[0]->category_id)->Products;
but i don't know that how i get url of product that i get from this request?
please let me know how i can achieve this
Thanks
Please or to participate in this conversation.