5 use Illuminate\Database\Eloquent\Factories\HasFactory;
6 use Illuminate\Foundation\Auth\User as Authenticatable;
7 use Illuminate\Notifications\Notifiable;
8 use Laravel\Sanctum\HasApiTokens;
11 class User extends Authenticatable
13 use HasApiTokens, HasFactory, Notifiable;
15 public function isAdmin() {
16 return $this->role === 'admin';
19 public function isParticipant(Tournament $tournament) {
20 foreach ($tournament->participants as $participant) {
21 if ($participant->user_id == $this->id) {
28 public function isRunner(Tournament $tournament) {
29 foreach ($tournament->participants as $participant) {
30 if ($participant->user_id == $this->id) {
31 return in_array('runner', $participant->roles);
37 public function isTournamentAdmin(Tournament $tournament) {
38 foreach ($tournament->participants as $participant) {
39 if ($participant->user_id == $this->id) {
40 return in_array('admin', $participant->roles);
46 public function isTournamentCrew(Tournament $tournament) {
47 return $this->isTournamentAdmin($tournament) || $this->isTournamentMonitor($tournament);
50 public function isTournamentMonitor(Tournament $tournament) {
51 foreach ($tournament->participants as $participant) {
52 if ($participant->user_id == $this->id) {
53 return in_array('monitor', $participant->roles);
60 public function participation() {
61 return $this->hasMany(Participant::class);
64 public function results() {
65 return $this->hasMany(Result::class);
68 public function rounds() {
69 return $this->belongsToMany(Round::class, 'results');
72 public function tournaments() {
73 return $this->belongsToMany(Tournament::class, 'participants');
77 public function round_first() {
78 return $this->rounds()
79 ->where('locked', true)
80 ->where('no_record', false)
81 ->wherePivot('forfeit', false)
82 ->wherePivot('placement', 1);
85 public function round_second() {
86 return $this->rounds()
87 ->where('locked', true)
88 ->where('no_record', false)
89 ->wherePivot('forfeit', false)
90 ->wherePivot('placement', 2);
93 public function round_third() {
94 return $this->rounds()
95 ->where('locked', true)
96 ->where('no_record', false)
97 ->wherePivot('forfeit', false)
98 ->wherePivot('placement', 3);
101 public function tournament_first() {
102 return $this->tournaments()
103 ->where('locked', true)
104 ->where('no_record', false)
105 ->wherePivot('placement', 1);
108 public function tournament_second() {
109 return $this->tournaments()
110 ->where('locked', true)
111 ->where('no_record', false)
112 ->wherePivot('placement', 2);
115 public function tournament_third() {
116 return $this->tournaments()
117 ->where('locked', true)
118 ->where('no_record', false)
119 ->wherePivot('placement', 3);
124 * The attributes that are mass assignable.
128 protected $fillable = [
142 * The attributes that should be hidden for serialization.
146 protected $hidden = [
154 * The attributes that should be cast.
160 'username' => 'string',
161 'discriminator' => 'string',
163 'avatar' => 'string',
164 'verified' => 'boolean',
165 'locale' => 'string',
166 'mfa_enabled' => 'boolean',
167 'refresh_token' => 'encrypted',