dharmendrarao
1 year ago

How i can get data from multiple models

Posted 1 year ago by dharmendrarao

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 sign in or create an account to participate in this conversation.