Category::categorizable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php namespace Arcanedev\Taxonomies\Models;
2
3
use Arcanedev\LaravelNestedSet\NodeTrait;
4
use Arcanedev\Taxonomies\Bases\Model;
5
6
/**
7
 * Class     Category
8
 *
9
 * @package  Arcanedev\Taxonomies\Models
10
 * @author   ARCANEDEV <[email protected]>
11
 *
12
 * @property  int             id
13
 * @property  string          name
14
 * @property  string          slug
15
 * @property  string          description
16
 * @property  int             _lft
17
 * @property  int             _rgt
18
 * @property  int             parent_id
19
 * @property  \Carbon\Carbon  created_at
20
 * @property  \Carbon\Carbon  updated_at
21
 */
22
class Category extends Model
23
{
24
    /* ------------------------------------------------------------------------------------------------
25
     |  Traits
26
     | ------------------------------------------------------------------------------------------------
27
     */
28
    use NodeTrait;
29
30
    /* ------------------------------------------------------------------------------------------------
31
     |  Properties
32
     | ------------------------------------------------------------------------------------------------
33
     */
34
    /**
35
     * The attributes that aren't mass assignable.
36
     *
37
     * @var array
38
     */
39
    protected $fillable = [
40
        'name', 'slug', 'description', '_lft', '_rgt', 'parent_id',
41
    ];
42
43
    /**
44
     * Indicates if the model should be timestamped.
45
     *
46
     * @var bool
47
     */
48
    public $timestamps = true;
49
50
    /* ------------------------------------------------------------------------------------------------
51
     |  Relationships
52
     | ------------------------------------------------------------------------------------------------
53
     */
54
    /**
55
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
56
     */
57
    public function categorizable()
58
    {
59
        return $this->morphTo();
60
    }
61
62
    /**
63
     * @param  string  $related
64
     *
65
     * @return \Illuminate\Database\Eloquent\Relations\MorphToMany
66
     */
67
    public function entries($related)
68
    {
69
        return $this->morphedByMany(
70
            $related,
71
            config('taxonomies.categories.morph.name', 'categorizable'),
72
            config('taxonomies.categories.morph.table', 'categories_relations')
73
        );
74
    }
75
76
    /* ------------------------------------------------------------------------------------------------
77
     |  Other Functions
78
     | ------------------------------------------------------------------------------------------------
79
     */
80 9
    public static function tree()
81
    {
82 9
        return self::get()->toTree()->toArray();
83
    }
84
}
85