Level 16
Maybe something like this:
class User
{
public function exhibitions()
{
return $this->belongsToMany('Exhibition', 'exhibition_role', 'exhibition_id', 'role_id');
}
public function roles()
{
return $this->belongsToMany('Role', 'exhibition_role', 'user_id', 'role_id');
}
}
class Exhibition
{
public function users()
{
return $this->belongsToMany('User', 'exhibition_role', 'exhibition_id', 'user_id');
}
public function roles()
{
return $this->belongsToMany('Role', 'exhibition_role', 'exhibition_id', 'role_id');
}
}
class ExhibitionRole
{
public function user()
{
return $this->belongsTo('User');
}
public function exhibition()
{
return $this->belongsTo('Exhibition');
}
public function role()
{
return $this->belongsTo('Role');
}
}
class Role
{
public function users()
{
return $this->belongsToMany('User', 'exhibition_role', 'role_id', 'user_id');
}
public function exhibitions()
{
return $this->belongsToMany('Role', 'exhibition_role', 'exhibition_id', 'role_id');
}
}
Then create the following migrations (I listed just as pseudo-code):
- users table with fields: id, name, etc....
- exhibition_role table with fields: id, role_id, exhibition_id, user_id
- exhibitions table with fields: id, name, etc....
- roles table with fields: id, name, etc....
This may not be spot-on, but it should get your pretty close. :)