Связь между 4 таблицами Laravel
Всем привет, есть 3 модели фильтра
//Filter
class Filter extends Model
{
protected $fillable = [
'id',
'name',
'visible',
'visible_category',
];
//FilterAttribute
class FilterAttribute extends Model
{
protected $fillable = [
'id',
'filter_id',
'value',
];
}
// ProductAttribute
class ProductAttribute extends Model
{
protected $fillable = [
'id',
'filter_attr_id',
'product_id',
];
}
Мне нужно при получении товара выводить значения атрибутов фильтра для этого товара В моделе Product сделал такую связь
public function ProductAttribute()
{
return $this->belongsToMany(ProductAttribute::class, 'filter_attributes', 'filter_attr_id');
}
Вывожу так
$products = Product::where('autor_id', '=', $user_id)->with('ProductAttribute')->get();
Но получаю ошибку, подскажите как правильно организовать связь Ошибка:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'filter_attributes.filter_attr_id' in 'on clause' (SQL: select `filter_attributes`.*, `product_attributes`.`product_id` as `laravel_through_key` from `filter_attributes` inner join `product_attributes` on `product_attributes`.`id` = `filter_attributes`.`filter_attr_id` where `product_attributes`.`product_id` in (?))