Completed
Push — master ( cdd9f0...19e1c8 )
by Christopher
01:02
created

Post::path()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
    public function path()
61
    {
62
        return "/posts/{$this->slug}";
63
    }
64
}
65