refactoring

This commit is contained in:
Andras Bacsai
2023-08-29 14:36:17 +02:00
parent 2f9b7b188a
commit 291b9a84ef
23 changed files with 409 additions and 240 deletions

View File

@@ -91,29 +91,20 @@ class User extends Authenticatable implements SendsEmail
return $found_root_team->count() > 0;
}
public function personalTeam()
{
return $this->teams()->where('personal_team', true)->first();
}
public function currentTeam()
{
return $this->teams()->where('team_id', session('currentTeam')->id)->first();
return session('currentTeam');
}
public function otherTeams()
{
$team_id = currentTeam()->id;
return auth()->user()->teams->filter(function ($team) use ($team_id) {
return $team->id != $team_id;
return auth()->user()->teams->filter(function ($team) {
return $team->id != currentTeam()->id;
});
}
public function role()
{
if ($this->teams()->where('team_id', 0)->first()) {
return 'admin';
}
return $this->teams()->where('team_id', currentTeam()->id)->first()->pivot->role;
return session('currentTeam')->pivot->role;
}
}