Why store the diver roles in the db? Do you expect to have more than just a few diver roles? If so, I would probably reach for polymorphism and make each type of role its own class.
class Diver {
public function role() {
return $this->morphsMany(Diver::class,'diver');
}
}
class Student {
public function diver() {
return $this->morphTo();
}
}
class Photographer {
public function diver() {
return $this->morphTo();
}
}
class OtherRole {
public function diver() {
return $this->morphTo();
}
}
Otherwise, if you only have a few roles and you don't want to use polymorphism, consider using a helper class to store information about the roles. The roles don't really need to be stored in the db, since you would have to add additional relationships to App\Dive if more roles were added to the db.
// App\DiverRole
class DiverRole {
const STUDENT = 1;
const PHOTOGRAPHER = 2;
const INSTRUCTOR = 3;
}
// App\Dive
...
public function students(){
return $this->belongsToMany(User::class)
->wherePivot('diver_role_id', DiverRole::STUDENT);
}
public function photographers(){
return $this->belongsToMany(User::class)
->wherePivot('diver_role_id', DiverRole::PHOTOGRAPHER);
}
public function instructors(){
return $this->belongsToMany(User::class)
->wherePivot('diver_role_id', DiverRole::INSTRUCTOR);
}
...
Hope this helps.