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