You have two options here. Extending the user as you do now, or use something like a role in the users table. Then everything stays a User, but you have to query specifically for athletes or coaches.
Looking at your current example it would be better to continue with this. However, I would still recommend you to add a role or type column to your users table. The reason for this is that it makes it a lot easier to query them
class Athlete extends User
{
protected static function booted()
{
static::addGlobalScope('athlete', function (Builder $builder) {
$builder->where('type', 'athlete');
});
}
}
This way you can simply do Athele::all() and you will only get users back with that specific type.
For your relationships, you need to be a little bit creative. You need a many-to-many relation between athletes and coaches. Since you extend the User model you only have those ids, but you can name them whatever you want. So this should work
class Athlete extends User
{
public function coaches()
{
return $this->belongsToMany(Coach::class, 'athlete_coach', 'athlete_id', 'coach_id');
}
}
class Coach extends User
{
public function athletes()
{
return $this->belongsToMany(Athlete::class, 'athlete_coach', 'coach_id', 'athlete_id');
}
}
Your migration might look like this
Schema::create('athlete_coach', function (Blueprint $table) {
$table->bigInteger('athlete_id')->unsigned();
$table->bigInteger('coach_id')->unsigned();
$table->foreign('athlete_id')->references('id')->on('users');
$table->foreign('coach_id')->references('id')->on('users');
});
Let me know if that makes sense ;)