1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Pages\Models; |
6
|
|
|
|
7
|
|
|
use Rinvex\Tags\Traits\Taggable; |
8
|
|
|
use Rinvex\Tenants\Traits\Tenantable; |
9
|
|
|
use Cortex\Foundation\Traits\Auditable; |
10
|
|
|
use Rinvex\Pages\Models\Page as BasePage; |
11
|
|
|
use Spatie\MediaLibrary\HasMedia\HasMedia; |
12
|
|
|
use Spatie\Activitylog\Traits\LogsActivity; |
13
|
|
|
use Spatie\MediaLibrary\HasMedia\HasMediaTrait; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Cortex\Pages\Models\Page. |
17
|
|
|
* |
18
|
|
|
* @property int $id |
19
|
|
|
* @property string $uri |
20
|
|
|
* @property string $name |
21
|
|
|
* @property string $route |
22
|
|
|
* @property string $domain |
23
|
|
|
* @property string $middleware |
24
|
|
|
* @property array $title |
25
|
|
|
* @property array $subtitle |
26
|
|
|
* @property array $excerpt |
27
|
|
|
* @property array $content |
28
|
|
|
* @property string $view |
29
|
|
|
* @property bool $is_active |
30
|
|
|
* @property int $sort_order |
31
|
|
|
* @property \Carbon\Carbon|null $created_at |
32
|
|
|
* @property \Carbon\Carbon|null $updated_at |
33
|
|
|
* @property \Carbon\Carbon $deleted_at |
34
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\Cortex\Foundation\Models\Log[] $activity |
35
|
|
|
* @property \Illuminate\Database\Eloquent\Collection|\Cortex\Tenants\Models\Tenant[] $tenants |
36
|
|
|
* |
37
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page ordered($direction = 'asc') |
38
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereContent($value) |
39
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereCreatedAt($value) |
40
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereDeletedAt($value) |
41
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereDomain($value) |
42
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereExcerpt($value) |
43
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereId($value) |
44
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereIsActive($value) |
45
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereMiddleware($value) |
46
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereRoute($value) |
47
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereName($value) |
48
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereSortOrder($value) |
49
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereSubtitle($value) |
50
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereTitle($value) |
51
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereUpdatedAt($value) |
52
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereUri($value) |
53
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page whereView($value) |
54
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page withAllTenants($tenants, $group = null) |
|
|
|
|
55
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page withAnyTenants($tenants, $group = null) |
|
|
|
|
56
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page withTenants($tenants, $group = null) |
57
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page withoutAnyTenants() |
58
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Pages\Models\Page withoutTenants($tenants, $group = null) |
|
|
|
|
59
|
|
|
* @mixin \Eloquent |
60
|
|
|
*/ |
61
|
|
|
class Page extends BasePage implements HasMedia |
62
|
|
|
{ |
63
|
|
|
use Taggable; |
64
|
|
|
use Auditable; |
65
|
|
|
use Tenantable; |
66
|
|
|
use LogsActivity; |
67
|
|
|
use HasMediaTrait; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Indicates whether to log only dirty attributes or all. |
71
|
|
|
* |
72
|
|
|
* @var bool |
73
|
|
|
*/ |
74
|
|
|
protected static $logOnlyDirty = true; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* The attributes that are logged on change. |
78
|
|
|
* |
79
|
|
|
* @var array |
80
|
|
|
*/ |
81
|
|
|
protected static $logFillable = true; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* The attributes that are ignored on change. |
85
|
|
|
* |
86
|
|
|
* @var array |
87
|
|
|
*/ |
88
|
|
|
protected static $ignoreChangedAttributes = [ |
89
|
|
|
'created_at', |
90
|
|
|
'updated_at', |
91
|
|
|
'deleted_at', |
92
|
|
|
]; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Create a new Eloquent model instance. |
96
|
|
|
* |
97
|
|
|
* @param array $attributes |
98
|
|
|
*/ |
99
|
|
|
public function __construct(array $attributes = []) |
100
|
|
|
{ |
101
|
|
|
parent::__construct($attributes); |
102
|
|
|
|
103
|
|
|
$this->setTable(config('rinvex.pages.tables.pages')); |
104
|
|
|
$this->setRules([ |
105
|
|
|
'uri' => 'required|regex:/^([0-9a-z\/_-]+)$/|max:150|unique:'.config('rinvex.pages.tables.pages').',uri,NULL,id,domain,'.($this->domain ?? 'null'), |
|
|
|
|
106
|
|
|
'name' => 'required|alpha_dash|max:150|unique:'.config('rinvex.pages.tables.pages').',name,NULL,id,domain,'.($this->domain ?? 'null'), |
|
|
|
|
107
|
|
|
'route' => 'required|regex:/^([0-9a-z\._-]+)$/|max:150|unique:'.config('rinvex.pages.tables.pages').',route,NULL,id,domain,'.($this->domain ?? 'null'), |
|
|
|
|
108
|
|
|
'domain' => 'nullable|string|max:150', |
109
|
|
|
'middleware' => 'nullable|string|max:150', |
110
|
|
|
'title' => 'required|string|max:150', |
111
|
|
|
'subtitle' => 'nullable|string|max:150', |
112
|
|
|
'excerpt' => 'nullable|string|max:10000', |
113
|
|
|
'content' => 'nullable|string|max:10000000', |
114
|
|
|
'view' => 'required|string|max:150', |
115
|
|
|
'is_active' => 'sometimes|boolean', |
116
|
|
|
'sort_order' => 'nullable|integer|max:10000000', |
117
|
|
|
'tags' => 'nullable|array', |
118
|
|
|
]); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Get the route key for the model. |
123
|
|
|
* |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
|
|
public function getRouteKeyName(): string |
127
|
|
|
{ |
128
|
|
|
return 'name'; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.