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