I don't think a user_tests table is necessary in this instance. If I understand your domain correctly, a user has many tests and a test has 1 user. So the following schema should work:
[users table] id, name, ...
[tests table] id, user_id, title, score, ...
Then in the User model:
public function tests()
{
return $this->hasMany('App\Test');
}
Then in the Test model
public function student()
{
return $this->belongsTo('App\User');
}
joedixon liked this reply
thanks, in the meanwhile I realized I need a many to many for this relation...
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community