Passed
Pull Request — master (#95)
by Fèvre
22:54 queued 17:29
created

DiscussPost::casts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Models;
6
7
use Eloquence\Behaviours\CountCache\CountedBy;
8
use Eloquence\Behaviours\CountCache\HasCounts;
9
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
10
use Illuminate\Database\Eloquent\Relations\BelongsTo;
11
use Illuminate\Database\Eloquent\Relations\HasOne;
12
use Xetaio\Mentions\Models\Traits\HasMentionsTrait;
13
use Xetaravel\Models\Gates\FloodGate;
14
use Xetaravel\Models\Presenters\DiscussPostPresenter;
15
use Xetaravel\Observers\DiscussPostObserver;
16
17
#[ObservedBy([DiscussPostObserver::class])]
18
class DiscussPost extends Model
19
{
20
    use DiscussPostPresenter;
0 ignored issues
show
Bug introduced by
The trait Xetaravel\Models\Presenters\DiscussPostPresenter requires the property $content which is not provided by Xetaravel\Models\DiscussPost.
Loading history...
21
    use FloodGate;
22
    use HasCounts;
23
    use HasMentionsTrait;
24
25
    /**
26
     * The attributes that are mass assignable.
27
     *
28
     * @var array
29
     */
30
    protected $fillable = [
31
        'user_id',
32
        'conversation_id',
33
        'content',
34
        'is_edited'
35
    ];
36
37
    /**
38
     * The accessors to append to the model's array form.
39
     *
40
     * @var array
41
     */
42
    protected $appends = [
43
        'content_markdown',
44
        'post_url'
45
    ];
46
47
    /**
48
     * The attributes that should be cast.
49
     */
50
    protected function casts(): array
51
    {
52
        return [
53
            'edited_at' => 'datetime'
54
        ];
55
    }
56
57
    /**
58
     * Get the user that owns the post.
59
     *
60
     * @return BelongsTo
61
     */
62
    #[CountedBy(as: 'discuss_post_count')]
63
    public function user(): BelongsTo
64
    {
65
        return $this->belongsTo(User::class);
66
    }
67
68
    /**
69
     * Get the conversation that owns the post.
70
     *
71
     * @return BelongsTo
72
     */
73
    #[CountedBy(as: 'post_count')]
74
    public function conversation(): BelongsTo
75
    {
76
        return $this->belongsTo(DiscussConversation::class);
77
    }
78
79
    /**
80
     * Get the user that edited the post.
81
     *
82
     * @return HasOne
83
     */
84
    public function editedUser(): HasOne
85
    {
86
        return $this->hasOne(User::class, 'id', 'edited_user_id');
87
    }
88
}
89