-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEvent.php
91 lines (82 loc) · 2.4 KB
/
Event.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace App\Models;
use App\Utils\StringUtil;
use Database\Factories\EventFactory;
use Eloquent;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Carbon;
/**
* App\Models\Event
*
* @property int $id
* @property string $name
* @property Carbon|null $start
* @property Carbon|null $end
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property-read Collection|User[] $attendees
* @property-read int|null $attendees_count
* @property-read Collection|Role[] $roles
* @property-read int|null $roles_count
*
* @method static EventFactory factory(...$parameters)
* @method static Builder|Event newModelQuery()
* @method static Builder|Event newQuery()
* @method static Builder|Event query()
* @method static Builder|Event whereCreatedAt($value)
* @method static Builder|Event whereEnd($value)
* @method static Builder|Event whereId($value)
* @method static Builder|Event whereName($value)
* @method static Builder|Event whereStart($value)
* @method static Builder|Event whereUpdatedAt($value)
*
* @property-read string $short_name
* @property-read Collection|\App\Models\Payment[] $payments
* @property-read int|null $payments_count
*
* @mixin Eloquent
*/
class Event extends Model
{
use HasFactory, HasRoles;
/**
* The attributes that should be cast.
*/
protected $casts = [
'start' => 'datetime',
'end' => 'datetime',
];
/**
* @return Collection<User>
*/
public function attendeesSortedByFirstName(): Collection
{
return $this
->attendees()
->orderBy('first_name')
->get();
}
/**
* @return BelongsToMany<User>
*/
public function attendees(): BelongsToMany
{
return $this->belongsToMany(User::class);
}
public function payments(): HasMany
{
return $this->hasMany(Payment::class);
}
/** @noinspection PhpUnused */
public function getShortNameAttribute(): string
{
$yearComponent = $this->start?->year ?? 0;
$nameComponent = StringUtil::firstCharacterOfEachWord($this->name);
return $nameComponent.'-'.$yearComponent;
}
}