DiscussPost::editedUser()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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_solved',
35
        'is_edited'
36
    ];
37
38
    /**
39
     * The accessors to append to the model's array form.
40
     *
41
     * @var array
42
     */
43
    protected $appends = [
44
        'content_markdown',
45
        'post_url'
46
    ];
47
48
    /**
49
     * The attributes that should be cast.
50
     */
51
    protected function casts(): array
52
    {
53
        return [
54
            'is_edited' => 'boolean'
55
        ];
56
    }
57
58
    /**
59
     * Get the user that owns the post.
60
     *
61
     * @return BelongsTo
62
     */
63
    #[CountedBy(as: 'discuss_post_count')]
64
    public function user(): BelongsTo
65
    {
66
        return $this->belongsTo(User::class)->withTrashed();
67
    }
68
69
    /**
70
     * Get the conversation that owns the post.
71
     *
72
     * @return BelongsTo
73
     */
74
    #[CountedBy(as: 'post_count')]
75
    public function conversation(): BelongsTo
76
    {
77
        return $this->belongsTo(DiscussConversation::class);
78
    }
79
80
    /**
81
     * Get the user that edited the post.
82
     *
83
     * @return HasOne
84
     */
85
    public function editedUser(): HasOne
86
    {
87
        return $this->hasOne(User::class, 'id', 'edited_user_id')->withTrashed();
88
    }
89
}
90