Completed
Push — master ( 7bbc02...faeb83 )
by Marcel
13s queued 10s
created

Comment::disapprove()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace BeyondCode\Comments;
4
5
use Exception;
6
use Illuminate\Database\Eloquent\Model;
7
use BeyondCode\Comments\Traits\HasComments;
8
9
class Comment extends Model
10
{
11
    use HasComments;
12
13
    protected $fillable = [
14
        'comment',
15
        'user_id',
16
        'is_approved'
17
    ];
18
19
    protected $casts = [
20
        'is_approved' => 'boolean'
21
    ];
22
23
    public function scopeApproved($query)
24
    {
25
        return $query->where('is_approved', true);
26
    }
27
28
    public function commentable()
29
    {
30
        return $this->morphTo();
31
    }
32
33
    public function commentator()
34
    {
35
        return $this->belongsTo($this->getAuthModelName(), 'user_id');
36
    }
37
38
    public function approve()
39
    {
40
        $this->update([
41
            'is_approved' => true,
42
        ]);
43
44
        return $this;
45
    }
46
  
47
    public function disapprove()
48
    {
49
        $this->update([
50
            'is_approved' => false,
51
        ]);
52
53
        return $this;
54
    }
55
56
    protected function getAuthModelName()
57
    {
58
        if (config('comments.user_model')) {
59
            return config('comments.user_model');
60
        }
61
62
        if (!is_null(config('auth.providers.users.model'))) {
63
            return config('auth.providers.users.model');
64
        }
65
66
        throw new Exception('Could not determine the commentator model name.');
67
    }
68
69
}
70