table:
users id questions id user_questions user_id question_id desc // 附加字段 unique(user_id, question_id)
大致这个样子,定义模型关系的时候
return $this->belongsToMany('AppRole')->withPivot('column1', 'column2');
获取数据的时候
$user = AppUser::find(1); foreach ($user->roles as $role) { echo $role->pivot->column1; }
2.1m questions
2.1m answers
60 comments
57.0k users