У меня есть таблица products
с brand_id
и таблица category_products
с product_id
и category_id
.
Модель My Products:
class Product extends Model
{
public function categories() {
return $this->belongsToMany(Category::class)->withTimestamps();
}
}
Модель моих брендов:
class Brand extends Model
{
public function products() {
return $this->hasMany(Product::class)->with(['categories']);
}
}
Мой вопрос: как я могу получить продукты из экземпляра Brand
, который принадлежит определенной категории?
$brand = App\Brand::find(1);
/*
I want to be able to do something in the likes of :
*/
$brand->products_which_are_under_this_category