0
我需要獲取必須與存儲在數據透視表中的值匹配的模型,但不幸的是我無法獲得解決方案。Laravel Eloquent獲得與數據透視表中的值匹配的關係
這裏是我的架構
PEROPERTY TABLE
id
FILTER TABLE
id
FILTER_OPTION TABLE
id
filterId
FILTER_OPTION_TRANSLATE TABLE
optionId
languageId
title
PROPERTY_FILTER TABLE
propertyId
filterId
optionId
我wanto做的是:
@foreach($property->filters as $filter)
{{ $filter->option->translate->title }}
@endforeach
但在這裏,對我來說,問題是怎麼說的獲取選項中PROPERTY_FILTER表匹配optionId
我的型號:
PROPERTY MODEL
public function filters()
{
return $this->belongsToMany(Filter::class, 'PROPERTY_FILTER','propertyId','filterId');
}
FILTER MODEL
public function option()
{
return $this->hasMany(Filter_Option::class, 'filterId');
}
FILTER OPTION MODEL
public function translate()
{
return $this
->hasOne(Filter_Option_Translate::class, 'optionId')
->where('langId', currentLanguage()->langId);
}
我希望我能得到一些幫助,從現在開始感謝。