Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
Message | |
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
sender | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
receiver | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Engelsystem\Models; |
6 | |
7 | use Engelsystem\Models\User\User; |
8 | use Engelsystem\Models\User\UsesUserModel; |
9 | use Illuminate\Database\Eloquent\Builder; |
10 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
11 | use Illuminate\Database\Eloquent\Relations\BelongsTo; |
12 | use Illuminate\Support\Carbon; |
13 | |
14 | /** |
15 | * This class represents a message send trough the system. |
16 | * |
17 | * @property int $id |
18 | * @property int $receiver_id |
19 | * @property bool $read |
20 | * @property string $text |
21 | * @property Carbon|null $created_at |
22 | * @property Carbon|null $updated_at |
23 | * |
24 | * @property-read User $sender |
25 | * @property-read User $receiver |
26 | * |
27 | * @method static Builder|Message whereId($value) |
28 | * @method static Builder|Message whereUserId($value) |
29 | * @method static Builder|Message whereReceiverId($value) |
30 | * @method static Builder|Message whereRead($value) |
31 | * @method static Builder|Message whereText($value) |
32 | * @method static Builder|Message whereCreatedAt($value) |
33 | * @method static Builder|Message whereUpdatedAt($value) |
34 | */ |
35 | class Message extends BaseModel |
36 | { |
37 | use HasFactory; |
38 | use UsesUserModel; |
39 | |
40 | /** @var bool enable timestamps */ |
41 | public $timestamps = true; // phpcs:ignore |
42 | |
43 | /** @var array<string, string> */ |
44 | protected $casts = [ // phpcs:ignore |
45 | 'user_id' => 'integer', |
46 | 'receiver_id' => 'integer', |
47 | 'read' => 'boolean', |
48 | ]; |
49 | |
50 | /** @var array<string> */ |
51 | protected $fillable = [ // phpcs:ignore |
52 | 'user_id', |
53 | 'receiver_id', |
54 | 'read', |
55 | 'text', |
56 | ]; |
57 | |
58 | /** @var array<string, bool> */ |
59 | protected $attributes = [ // phpcs:ignore |
60 | 'read' => false, |
61 | ]; |
62 | |
63 | public function sender(): BelongsTo |
64 | { |
65 | return $this->belongsTo(User::class, 'user_id'); |
66 | } |
67 | |
68 | public function receiver(): BelongsTo |
69 | { |
70 | return $this->belongsTo(User::class, 'receiver_id'); |
71 | } |
72 | } |