Tagged::taggable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
c 2
b 1
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Conner\Tagging\Model;
4
5
use Conner\Tagging\TaggingUtility;
6
use Illuminate\Database\Eloquent\Builder;
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Database\Eloquent\Relations\BelongsTo;
9
use Illuminate\Database\Eloquent\Relations\MorphTo;
10
11
/**
12
 * @mixin Model
13
 * @mixin Builder
14
 *
15
 * @property int id
16
 * @property string taggable_id
17
 * @property string taggable_type
18
 * @property string tag_name
19
 * @property string tag_slug
20
 * @property Tag tag
21
 */
22
class Tagged extends Model
23
{
24
    protected $table = 'tagging_tagged';
25
26
    public $timestamps = false;
27
28
    protected $fillable = ['tag_name', 'tag_slug'];
29
30
    public function __construct(array $attributes = [])
31
    {
32
        parent::__construct($attributes);
33
34
        $this->connection = config('tagging.connection');
35
    }
36
37
    /**
38
     * Morph to the tag
39
     *
40
     * @return MorphTo
41
     */
42
    public function taggable()
43
    {
44
        return $this->morphTo();
45
    }
46
47
    /**
48
     * Get instance of tag linked to the tagged value
49
     *
50
     * @return BelongsTo
51
     */
52
    public function tag()
53
    {
54
        $model = TaggingUtility::tagModelString();
55
56
        return $this->belongsTo($model, 'tag_slug', 'slug');
57
    }
58
}
59