You can use this
users
-----
id
name
...
questions
---------
id
title
answers
...
user_answers
------------
id
question_id
answers ( this answers user will compare with table question field answers )
user_id
or this
users
-----
id
name
...
questions
---------
id
title
...
answers
-------
id
question_id
answers
user_answers
------------
id
question_id
answers ( this answers user will compare with table answers field answers )
user_id
Now I have this but not sure if relationships are correct. How can I update or insert if answers are nor exist in my answer_user table?
class Question extends Model
{
public function answer()
{
return $this->hasMany('App\Answer');
}
}
class Answer extends Model
{
public function question()
{
return $this->belongsTo('App\Question');
}
}
class User extends Authenticatable
{
public function answers()
{
return $this->belongsToMany('App\Answer');
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community