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('placement', 1);
67 public function round_second() {
68 return $this->rounds()
69 ->where('locked', true)
70 ->where('no_record', false)
71 ->wherePivot('placement', 2);
74 public function round_third() {
75 return $this->rounds()
76 ->where('locked', true)
77 ->where('no_record', false)
78 ->wherePivot('placement', 3);
81 public function tournament_first() {
82 return $this->tournaments()
83 ->where('locked', true)
84 ->where('no_record', false)
85 ->wherePivot('placement', 1);
88 public function tournament_second() {
89 return $this->tournaments()
90 ->where('locked', true)
91 ->where('no_record', false)
92 ->wherePivot('placement', 2);
95 public function tournament_third() {
96 return $this->tournaments()
97 ->where('locked', true)
98 ->where('no_record', false)
99 ->wherePivot('placement', 3);
104 * The attributes that are mass assignable.
108 protected $fillable = [
122 * The attributes that should be hidden for serialization.
126 protected $hidden = [
134 * The attributes that should be cast.
140 'username' => 'string',
141 'discriminator' => 'string',
143 'avatar' => 'string',
144 'verified' => 'boolean',
145 'locale' => 'string',
146 'mfa_enabled' => 'boolean',
147 'refresh_token' => 'encrypted',