Sunday, April 16, 2017

Laravel complicated relationship approach?

Users(students) all have other users(teachers) assigned to them along with a type for example 1st reviewer or coordinator. Now when a student creates an assessment, the assigned reviewers get the option to accept or decline.

The problem I have is that I cant find a laravel way to make the reviewers aware of the assessments.

Heres a picture of my Schema. http://image.prntscr.com/image/571a8bfdc0cf4964973db336eda287e0.png

Heres part of my user model

public function roles()
{
    return $this->belongsTo(Role::class, 'role');
}

public function reviewers()
{
    return $this->hasMany(Reviewer::class, 'student');
}
public function students()
{
    return $this->hasMany(Reviewer::class, 'teacher');
}
public function assessments()
{
    return $this->hasMany(Assessment::class, 'user_id');
}

Here are the queries and lastly the query I cant figure out.

$student->reviewers => Collection of teachers 
$teacher->students => Collection of students 

$student->assessments => Collection of assessments 
$teacher->assessments => ??? 



via Macdows

Advertisement