Tag   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 87
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
A getRouteKeyName() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Tags\Models;
6
7
use Rinvex\Tags\Models\Tag as BaseTag;
8
use Cortex\Foundation\Traits\Auditable;
9
use Rinvex\Support\Traits\HashidsTrait;
10
use Spatie\Activitylog\Traits\LogsActivity;
11
12
/**
13
 * Cortex\Tags\Models\Tag.
14
 *
15
 * @property int                                                                           $id
16
 * @property string                                                                        $slug
17
 * @property array                                                                         $name
18
 * @property array                                                                         $description
19
 * @property int                                                                           $sort_order
20
 * @property string                                                                        $group
21
 * @property string                                                                        $style
22
 * @property string                                                                        $icon
23
 * @property \Carbon\Carbon|null                                                           $created_at
24
 * @property \Carbon\Carbon|null                                                           $updated_at
25
 * @property \Carbon\Carbon|null                                                           $deleted_at
26
 * @property-read \Illuminate\Database\Eloquent\Collection|\Cortex\Foundation\Models\Log[] $activity
27
 *
28
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tags\Models\Tag ordered($direction = 'asc')
29
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tags\Models\Tag whereCreatedAt($value)
30
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tags\Models\Tag whereDeletedAt($value)
31
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tags\Models\Tag whereDescription($value)
32
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tags\Models\Tag whereGroup($value)
33
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tags\Models\Tag whereIcon($value)
34
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tags\Models\Tag whereId($value)
35
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tags\Models\Tag whereName($value)
36
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tags\Models\Tag whereSlug($value)
37
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tags\Models\Tag whereSortOrder($value)
38
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tags\Models\Tag whereStyle($value)
39
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tags\Models\Tag whereUpdatedAt($value)
40
 * @mixin \Eloquent
41
 */
42
class Tag extends BaseTag
43
{
44
    use Auditable;
45
    use HashidsTrait;
46
    use LogsActivity;
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    protected $fillable = [
52
        'slug',
53
        'name',
54
        'description',
55
        'sort_order',
56
        'group',
57
        'style',
58
        'icon',
59
    ];
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    protected $casts = [
65
        'slug' => 'string',
66
        'sort_order' => 'integer',
67
        'group' => 'string',
68
        'style' => 'string',
69
        'icon' => 'string',
70
        'deleted_at' => 'datetime',
71
    ];
72
73
    /**
74
     * Indicates whether to log only dirty attributes or all.
75
     *
76
     * @var bool
77
     */
78
    protected static $logOnlyDirty = true;
79
80
    /**
81
     * The attributes that are logged on change.
82
     *
83
     * @var array
84
     */
85
    protected static $logFillable = true;
86
87
    /**
88
     * The attributes that are ignored on change.
89
     *
90
     * @var array
91
     */
92
    protected static $ignoreChangedAttributes = [
93
        'created_at',
94
        'updated_at',
95
        'deleted_at',
96
    ];
97
98
    /**
99
     * Create a new Eloquent model instance.
100
     *
101
     * @param array $attributes
102
     */
103
    public function __construct(array $attributes = [])
104
    {
105
        parent::__construct($attributes);
106
107
        $this->setTable(config('rinvex.tags.tables.tags'));
108
        $this->setRules([
109
            'slug' => 'required|alpha_dash|max:150|unique:'.config('rinvex.tags.tables.tags').',slug',
110
            'name' => 'required|string|max:150',
111
            'description' => 'nullable|string|max:10000',
112
            'sort_order' => 'nullable|integer|max:10000000',
113
            'group' => 'nullable|string|max:150',
114
            'style' => 'nullable|string|max:150',
115
            'icon' => 'nullable|string|max:150',
116
        ]);
117
    }
118
119
    /**
120
     * Get the route key for the model.
121
     *
122
     * @return string
123
     */
124
    public function getRouteKeyName()
125
    {
126
        return 'slug';
127
    }
128
}
129