]> git.localhorst.tv Git - alttp.git/blob - app/Models/User.php
show tournament participation in profile
[alttp.git] / app / Models / User.php
1 <?php
2
3 namespace App\Models;
4
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;
9
10
11 class User extends Authenticatable
12 {
13         use HasApiTokens, HasFactory, Notifiable;
14
15         public function isParticipant(Tournament $tournament) {
16                 foreach ($tournament->participants as $participant) {
17                         if ($participant->user->id == $this->id) {
18                                 return true;
19                         }
20                 }
21                 return false;
22         }
23
24         public function participation() {
25                 return $this->hasMany(Participant::class);
26         }
27
28         /**
29          * The attributes that are mass assignable.
30          *
31          * @var string[]
32          */
33         protected $fillable = [
34                 'id',
35                 'username',
36                 'discriminator',
37                 'email',
38                 'avatar',
39                 'verified',
40                 'locale',
41                 'mfa_enabled',
42                 'refresh_token',
43                 'role',
44         ];
45
46         /**
47          * The attributes that should be hidden for serialization.
48          *
49          * @var array
50          */
51         protected $hidden = [
52                 'email',
53                 'mfa_enabled',
54                 'refresh_token',
55                 'remember_token',
56         ];
57
58         /**
59          * The attributes that should be cast.
60          *
61          * @var array
62          */
63         protected $casts = [
64                 'id' => 'string',
65                 'username' => 'string',
66                 'discriminator' => 'string',
67                 'email' => 'string',
68                 'avatar' => 'string',
69                 'verified' => 'boolean',
70                 'locale' => 'string',
71                 'mfa_enabled' => 'boolean',
72                 'refresh_token' => 'encrypted',
73         ];
74 }