1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Attributes\Models; |
6
|
|
|
|
7
|
|
|
use Spatie\Activitylog\Traits\LogsActivity; |
8
|
|
|
use Rinvex\Attributes\Models\Attribute as BaseAttribute; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Cortex\Attributes\Models\Attribute. |
12
|
|
|
* |
13
|
|
|
* @property int $id |
14
|
|
|
* @property string $slug |
15
|
|
|
* @property array $name |
16
|
|
|
* @property array $description |
17
|
|
|
* @property int $sort_order |
18
|
|
|
* @property string $group |
19
|
|
|
* @property string $type |
20
|
|
|
* @property bool $is_required |
21
|
|
|
* @property bool $is_collection |
22
|
|
|
* @property string $default |
23
|
|
|
* @property \Carbon\Carbon $created_at |
24
|
|
|
* @property \Carbon\Carbon $updated_at |
25
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\Cortex\Foundation\Models\Log[] $activity |
26
|
|
|
* @property array $entities |
27
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\Rinvex\Fort\Models\User[] $values |
28
|
|
|
* |
29
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Attributes\Models\Attribute ordered($direction = 'asc') |
30
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Attributes\Models\Attribute whereCreatedAt($value) |
31
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Attributes\Models\Attribute whereDefault($value) |
32
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Attributes\Models\Attribute whereDescription($value) |
33
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Attributes\Models\Attribute whereGroup($value) |
34
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Attributes\Models\Attribute whereId($value) |
35
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Attributes\Models\Attribute whereIsCollection($value) |
36
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Attributes\Models\Attribute whereIsRequired($value) |
37
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Attributes\Models\Attribute whereName($value) |
38
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Attributes\Models\Attribute whereSlug($value) |
39
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Attributes\Models\Attribute whereSortOrder($value) |
40
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Attributes\Models\Attribute whereType($value) |
41
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Attributes\Models\Attribute whereUpdatedAt($value) |
42
|
|
|
* @mixin \Eloquent |
43
|
|
|
*/ |
44
|
|
|
class Attribute extends BaseAttribute |
45
|
|
|
{ |
46
|
|
|
use LogsActivity; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Indicates whether to log only dirty attributes or all. |
50
|
|
|
* |
51
|
|
|
* @var bool |
52
|
|
|
*/ |
53
|
|
|
protected static $logOnlyDirty = true; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* The attributes that are logged on change. |
57
|
|
|
* |
58
|
|
|
* @var array |
59
|
|
|
*/ |
60
|
|
|
protected static $logAttributes = [ |
61
|
|
|
'name', |
62
|
|
|
'slug', |
63
|
|
|
'description', |
64
|
|
|
'sort_order', |
65
|
|
|
'group', |
66
|
|
|
'type', |
67
|
|
|
'entities', |
68
|
|
|
'is_required', |
69
|
|
|
'is_collection', |
70
|
|
|
'default', |
71
|
|
|
]; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* The attributes that are ignored on change. |
75
|
|
|
* |
76
|
|
|
* @var array |
77
|
|
|
*/ |
78
|
|
|
protected static $ignoreChangedAttributes = [ |
|
|
|
|
79
|
|
|
'created_at', |
80
|
|
|
'updated_at', |
81
|
|
|
'deleted_at', |
82
|
|
|
]; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get the route key for the model. |
86
|
|
|
* |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public function getRouteKeyName() |
90
|
|
|
{ |
91
|
|
|
return 'slug'; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get the class name for polymorphic relations. |
96
|
|
|
* |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
public function getMorphClass() |
100
|
|
|
{ |
101
|
|
|
return 'attribute'; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.