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 isParticipant(Tournament $tournament) {
16 foreach ($tournament->participants as $participant) {
17 if ($participant->user_id == $this->id) {
24 public function isRunner(Tournament $tournament) {
25 foreach ($tournament->participants as $participant) {
26 if ($participant->user_id == $this->id) {
27 return in_array('runner', $participant->roles);
33 public function isTournamentAdmin(Tournament $tournament) {
34 foreach ($tournament->participants as $participant) {
35 if ($participant->user_id == $this->id) {
36 return in_array('admin', $participant->roles);
43 public function participation() {
44 return $this->hasMany(Participant::class);
47 public function results() {
48 return $this->hasMany(Result::class);
51 public function rounds() {
52 return $this->belongsToMany(Round::class, 'results');
55 public function tournaments() {
56 return $this->belongsToMany(Tournament::class, 'participants');
60 public function round_first() {
61 return $this->rounds()
62 ->where('locked', true)
63 ->where('no_record', false)
64 ->wherePivot('forfeit', false)
65 ->wherePivot('placement', 1);
68 public function round_second() {
69 return $this->rounds()
70 ->where('locked', true)
71 ->where('no_record', false)
72 ->wherePivot('forfeit', false)
73 ->wherePivot('placement', 2);
76 public function round_third() {
77 return $this->rounds()
78 ->where('locked', true)
79 ->where('no_record', false)
80 ->wherePivot('forfeit', false)
81 ->wherePivot('placement', 3);
84 public function tournament_first() {
85 return $this->tournaments()
86 ->where('locked', true)
87 ->where('no_record', false)
88 ->wherePivot('placement', 1);
91 public function tournament_second() {
92 return $this->tournaments()
93 ->where('locked', true)
94 ->where('no_record', false)
95 ->wherePivot('placement', 2);
98 public function tournament_third() {
99 return $this->tournaments()
100 ->where('locked', true)
101 ->where('no_record', false)
102 ->wherePivot('placement', 3);
107 * The attributes that are mass assignable.
111 protected $fillable = [
125 * The attributes that should be hidden for serialization.
129 protected $hidden = [
137 * The attributes that should be cast.
143 'username' => 'string',
144 'discriminator' => 'string',
146 'avatar' => 'string',
147 'verified' => 'boolean',
148 'locale' => 'string',
149 'mfa_enabled' => 'boolean',
150 'refresh_token' => 'encrypted',