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()
63 ->wherePivot('placement', 1);
66 public function round_second() {
67 return $this->rounds()
69 ->wherePivot('placement', 2);
72 public function round_third() {
73 return $this->rounds()
75 ->wherePivot('placement', 3);
78 public function tournament_first() {
79 return $this->tournaments()
81 ->wherePivot('placement', 1);
84 public function tournament_second() {
85 return $this->tournaments()
87 ->wherePivot('placement', 2);
90 public function tournament_third() {
91 return $this->tournaments()
93 ->wherePivot('placement', 3);
98 * The attributes that are mass assignable.
102 protected $fillable = [
116 * The attributes that should be hidden for serialization.
120 protected $hidden = [
128 * The attributes that should be cast.
134 'username' => 'string',
135 'discriminator' => 'string',
137 'avatar' => 'string',
138 'verified' => 'boolean',
139 'locale' => 'string',
140 'mfa_enabled' => 'boolean',
141 'refresh_token' => 'encrypted',