Completed
Push — master ( 8f843b...36053e )
by Christopher
01:12
created

Post   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 6
dl 0
loc 48
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A category() 0 4 1
A comments() 0 4 1
A tags() 0 4 1
A boot() 0 8 1
1
<?php
2
3
namespace Chriscreates\Blog;
4
5
use Chriscreates\Blog\Traits\IsAuthorable;
6
use Chriscreates\Blog\Traits\Post\PostAttributes;
7
use Chriscreates\Blog\Traits\Post\PostScopes;
8
use Chriscreates\Blog\Traits\Post\PostsHaveACategory;
9
use Chriscreates\Blog\Traits\Post\PostsHaveComments;
10
use Illuminate\Database\Eloquent\Model;
11
12
class Post extends Model
13
{
14
    use PostScopes,
15
    PostAttributes,
16
    IsAuthorable,
17
    PostsHaveComments,
18
    PostsHaveACategory;
19
20
    const PUBLISHED = 'published';
21
    const DRAFT = 'draft';
22
    const SCHEDULED = 'scheduled';
23
24
    protected $table = 'posts';
25
26
    protected $primaryKey = 'id';
27
28
    public $guarded = [];
29
30
    public $timestamps = true;
31
32
    protected $appends = ['tagsCount'];
33
34
    protected $dates = ['published_at'];
35
36
    public function category()
37
    {
38
        return $this->hasOne(Category::class, 'id', 'category_id');
39
    }
40
41
    public function comments()
42
    {
43
        return $this->morphMany(Comment::class, 'commentable');
44
    }
45
46
    public function tags()
47
    {
48
        return $this->morphToMany(Tag::class, 'taggable');
49
    }
50
51
    public static function boot()
52
    {
53
        parent::boot();
54
55
        static::deleted(function (Model $post) {
56
            $post->tags()->detach();
57
        });
58
    }
59
}
60