Yes, you can have an extra column in the intermediate table, so you have defined it correctly except the id field is unnecessary in the community_user table.
So the relationship can be setup as such:
// User.php
public function communities()
{
return $this->belongsToMany(Community::class)->withPivot('role');
}
// Community.php
public function users()
{
return $this->belongsToMany(User::class)->withPivot('role');
}
Perhaps user has to have many CommunityRole (CommunityRole belongs to user) where CommunityRole model also belongs to Role (Role has many CommunityRole). Also CommunityRole belongs to Community
It might be possible to use role_id on the community_user table but I don't know how you would differentiate between them when for instance asking for user's communities.
edit: I changed my mind above. This will be different to the email you got