This should work:
Categories:find(1)->products()->get()
If not, maybe show us the models.
It doesn't work. Categories model:
<?php
class Categories extends Eloquent {
protected $table = 'Categories';
public function products() {
return $this->belongsToMany('Products', 'product_category', 'product_id', 'category_id');
}
}
?>
Products model:
<?php
class Products extends Eloquent {
protected $table = 'Products';
public function categories() {
return $this->belongsToMany('Categories', 'product_category', 'product_id', 'category_id');
}
}
?>
Thanks DrPrez for the solution.I'll remember it.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community