1 | <?php
|
---|
2 |
|
---|
3 | namespace App\Models;
|
---|
4 |
|
---|
5 | use App\Enum\UserType;
|
---|
6 | use Illuminate\Contracts\Auth\MustVerifyEmail;
|
---|
7 | use Illuminate\Database\Eloquent\Factories\HasFactory;
|
---|
8 | use Illuminate\Database\Eloquent\Relations\HasMany;
|
---|
9 | use Illuminate\Database\Eloquent\Relations\HasOne;
|
---|
10 | use Illuminate\Foundation\Auth\User as Authenticatable;
|
---|
11 | use Illuminate\Notifications\Notifiable;
|
---|
12 | use Laravel\Cashier\Billable;
|
---|
13 | use Laravel\Sanctum\HasApiTokens;
|
---|
14 |
|
---|
15 | class User extends Authenticatable implements MustVerifyEmail
|
---|
16 | {
|
---|
17 | use HasApiTokens, HasFactory, Notifiable, Billable;
|
---|
18 |
|
---|
19 | protected $table = 'users';
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * The attributes that are mass assignable.
|
---|
23 | *
|
---|
24 | * @var array<int, string>
|
---|
25 | */
|
---|
26 | protected $fillable = [
|
---|
27 | 'email',
|
---|
28 | 'username',
|
---|
29 | 'password',
|
---|
30 | 'name',
|
---|
31 | 'profile_picture',
|
---|
32 | 'type',
|
---|
33 | ];
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * The attributes that should be hidden for serialization.
|
---|
37 | *
|
---|
38 | * @var array<int, string>
|
---|
39 | */
|
---|
40 | protected $hidden = [
|
---|
41 | 'password',
|
---|
42 | 'remember_token',
|
---|
43 | 'last_login_at',
|
---|
44 | 'last_login_ip',
|
---|
45 | 'user_agent',
|
---|
46 | ];
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * The attributes that are not mass assignable.
|
---|
50 | * @var string[]
|
---|
51 | */
|
---|
52 | protected $guarded = [
|
---|
53 | 'last_login_at',
|
---|
54 | 'last_login_ip',
|
---|
55 | 'user_agent',
|
---|
56 | ];
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * The attributes that should be cast.
|
---|
60 | *
|
---|
61 | * @var array<string, string>
|
---|
62 | */
|
---|
63 | protected $casts = [
|
---|
64 | 'email_verified_at' => 'datetime',
|
---|
65 | ];
|
---|
66 |
|
---|
67 | public function isOnboardingCompleted()
|
---|
68 | {
|
---|
69 | return true;
|
---|
70 | }
|
---|
71 |
|
---|
72 | public function role(): ?HasOne
|
---|
73 | {
|
---|
74 | return match ($this->type) {
|
---|
75 | UserType::ORGANIZER->value => $this->hasOne(Organizer::class),
|
---|
76 | UserType::MANAGER->value => $this->hasOne(Manager::class),
|
---|
77 | UserType::ARTIST->value => $this->hasOne(Artist::class),
|
---|
78 | };
|
---|
79 | }
|
---|
80 |
|
---|
81 | public function offer_comments(): HasMany
|
---|
82 | {
|
---|
83 | return $this->hasMany(OfferComment::class, 'author_id');
|
---|
84 | }
|
---|
85 | }
|
---|