Completed
Push — master ( 2b6acf...5f05b1 )
by Christopher
03:20
created

Post::category()   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 Chriscreate\Blog;
4
5
use Chriscreate\Blog\Traits\IsAuthorable;
6
use Chriscreate\Blog\Traits\Post\PostAttributes;
7
use Chriscreate\Blog\Traits\Post\PostScopes;
8
use Chriscreate\Blog\Traits\Post\PostsHaveComments;
9
use Illuminate\Database\Eloquent\Model;
10
11
class Post extends Model
12
{
13
    use PostScopes,
14
    PostAttributes,
15
    IsAuthorable,
16
    PostsHaveComments;
17
18
    const PUBLISHED = 'published';
19
    const DRAFT = 'draft';
20
    const SCHEDULED = 'scheduled';
21
22
    protected $table = 'posts';
23
24
    protected $primaryKey = 'id';
25
26
    public $guarded = [];
27
28
    public $timestamps = true;
29
30
    protected $appends = ['tagsCount'];
31
32
    protected $dates = ['published_at'];
33
34
    public function category()
35
    {
36
        return $this->hasOne(Category::class, 'id', 'category_id');
37
    }
38
39
    public function comments()
40
    {
41
        return $this->morphMany(Comment::class, 'commentable');
42
    }
43
44
    public function tags()
45
    {
46
        return $this->morphToMany(Tag::class, 'taggable');
47
    }
48
}
49