@atoagustyn
public function users()
{
return $this->belongsToMany(User::class, 'team_user', 'user_id', 'team_id');
}
should be
public function users()
{
return $this->belongsToMany(User::class, 'team_user', 'team_id', 'user_id');
}
For less noise code, but i like keep the pivot table name
public function users()
{
return $this->belongsToMany(User::class, 'team_user');
}
public function teams()
{
return $this->belongsToMany(Team::class, 'team_user');
}
source code
public function belongsToMany(
$related,
$table = null,
$foreignPivotKey = null,
$relatedPivotKey = null,
$parentKey = null,
$relatedKey = null,
$relation = null
)