Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

table:

users
    id
questions
    id
user_questions
    user_id
    question_id
    desc // 附加字段
    unique(user_id, question_id)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
353 views
Welcome To Ask or Share your Answers For Others

1 Answer

大致这个样子,定义模型关系的时候

return $this->belongsToMany('AppRole')->withPivot('column1', 'column2');

获取数据的时候

$user = AppUser::find(1);

foreach ($user->roles as $role) {
    echo $role->pivot->column1;
}



与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...