我得到了Tag
和Attendee
雄辯的模型,它們處於多對多的關係。樞軸表還有兩個屬性 - value_int
和value_string
。我Attendee
模式是這樣的:Laravel 5 - 根據型號和相關型號獲得特定的多對多關係ID
class Attendee extends Model
{
public $timestamps = false;
protected $fillable = [
'event_id'
];
public function tags() {
return $this->belongsToMany('App\Models\Tag', 'attendee_tag', 'attendee_id', 'tag_id')
->withPivot(['value_string', 'value_int']);
}
public function scoreTagValue($tag_id) {
return $this->tags->where('tag_id', '=', $tag_id)->first();
}
}
我想是獲得基於Attendee
模型和可變tag_id
樞紐值,所以我寫scoreTagValue
功能,但它總是返回null
,我不知道爲什麼:(我打電話這樣說: $attendee->scoreTagValue($tag_id)
感謝您的幫助:)
沒有,變量值,我在尋找,被稱爲比分:) – user3216673