How to get the content of additional fields of the intermediate table in Laravel orm many-to-many relationship?
仅有的幸福
仅有的幸福 2017-05-16 16:47:36
0
1
367

table:

users
    id
questions
    id
user_questions
    user_id
    question_id
    desc // 附加字段
    unique(user_id, question_id)
仅有的幸福
仅有的幸福

reply all(1)
过去多啦不再A梦

It looks roughly like this, when defining model relationships

return $this->belongsToMany('App\Role')->withPivot('column1', 'column2');

When getting data

$user = App\User::find(1);

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


Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template