Laravel связь между 3 таблицами
Есть 3 класса:
class Brand extends Model
{
protected $table = 'brands';
public function categories()
{
return $this->hasMany(Category::class);
}
public function products()
{
return $this->hasManyThrough(Product::class, Category::class);
}
}
class Category extends Model
{
protected $table = 'categories';
public function brand()
{
return $this->belongsTo(Brand::class);
}
public function products()
{
return $this->hasMany(Product::class);
}
}
class Product extends Model
{
protected $table = 'products';
public function category()
{
return $this->belongsTo(Category::class);
}
public function brand()
{
return $this->belongsTo(Brand::class);
}
}
На странице мне нужно вывести продукты с категорией чпу которого равен remkomplekty и c брендом чпу = aro
На SQL я делаю так:
SELECT p.*
FROM products p, categories c, brands b
WHERE p.category_id = c.id
AND c.slug = 'remkomplekty'
AND c.brand_id = b.id
AND b.slug = 'aro'
ORDER BY quantity DESC, CODE
Подскажите, какой будет логичный и красивый код для контроллера на "Языке Laravel". По сути нужно объединить 3 таблицы с условиями.
Варианты с DB::table не катят.