1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Tenants\Models; |
6
|
|
|
|
7
|
|
|
use Cortex\Auth\Models\Manager; |
8
|
|
|
use Rinvex\Tags\Traits\Taggable; |
9
|
|
|
use Cortex\Foundation\Traits\Auditable; |
10
|
|
|
use Rinvex\Support\Traits\HashidsTrait; |
11
|
|
|
use Spatie\MediaLibrary\HasMedia\HasMedia; |
12
|
|
|
use Spatie\Activitylog\Traits\LogsActivity; |
13
|
|
|
use Cortex\Foundation\Relations\BelongsToMorph; |
14
|
|
|
use Rinvex\Tenants\Models\Tenant as BaseTenant; |
15
|
|
|
use Spatie\MediaLibrary\HasMedia\HasMediaTrait; |
16
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphToMany; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Cortex\Tenants\Models\Tenant. |
20
|
|
|
* |
21
|
|
|
* @property int $id |
22
|
|
|
* @property string $slug |
23
|
|
|
* @property array $name |
24
|
|
|
* @property array $description |
25
|
|
|
* @property int $owner_id |
26
|
|
|
* @property string $owner_type |
27
|
|
|
* @property string $email |
28
|
|
|
* @property string $website |
29
|
|
|
* @property string $phone |
30
|
|
|
* @property string $language_code |
31
|
|
|
* @property string $country_code |
32
|
|
|
* @property string $state |
33
|
|
|
* @property string $city |
34
|
|
|
* @property string $address |
35
|
|
|
* @property string $postal_code |
36
|
|
|
* @property string $launch_date |
37
|
|
|
* @property string $timezone |
38
|
|
|
* @property string $currency |
39
|
|
|
* @property bool $is_active |
40
|
|
|
* @property string $style |
41
|
|
|
* @property \Carbon\Carbon|null $created_at |
42
|
|
|
* @property \Carbon\Carbon|null $updated_at |
43
|
|
|
* @property \Carbon\Carbon|null $deleted_at |
44
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\Cortex\Foundation\Models\Log[] $activity |
45
|
|
|
* @property-read \Cortex\Auth\Models\User|\Illuminate\Database\Eloquent\Model|\Eloquent $owner |
46
|
|
|
* |
47
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant ofOwner(\Illuminate\Database\Eloquent\Model $owner) |
|
|
|
|
48
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereAddress($value) |
49
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereCity($value) |
50
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereCountryCode($value) |
51
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereCreatedAt($value) |
52
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereCurrency($value) |
53
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereDeletedAt($value) |
54
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereDescription($value) |
55
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereEmail($value) |
56
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereId($value) |
57
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereIsActive($value) |
58
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereLanguageCode($value) |
59
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereLaunchDate($value) |
60
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereName($value) |
61
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereOwnerId($value) |
62
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereOwnerType($value) |
63
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant wherePhone($value) |
64
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant wherePostalCode($value) |
65
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereSlug($value) |
66
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereState($value) |
67
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereTimezone($value) |
68
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereUpdatedAt($value) |
69
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Tenants\Models\Tenant whereStyle($value) |
70
|
|
|
* @mixin \Eloquent |
71
|
|
|
*/ |
72
|
|
|
class Tenant extends BaseTenant implements HasMedia |
73
|
|
|
{ |
74
|
|
|
use Taggable; |
75
|
|
|
use Auditable; |
76
|
|
|
use LogsActivity; |
77
|
|
|
use HashidsTrait; |
78
|
|
|
use HasMediaTrait; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
*/ |
83
|
|
|
protected $fillable = [ |
84
|
|
|
'slug', |
85
|
|
|
'name', |
86
|
|
|
'description', |
87
|
|
|
'owner_id', |
88
|
|
|
'owner_type', |
89
|
|
|
'email', |
90
|
|
|
'website', |
91
|
|
|
'phone', |
92
|
|
|
'language_code', |
93
|
|
|
'country_code', |
94
|
|
|
'state', |
95
|
|
|
'city', |
96
|
|
|
'address', |
97
|
|
|
'postal_code', |
98
|
|
|
'launch_date', |
99
|
|
|
'timezone', |
100
|
|
|
'currency', |
101
|
|
|
'style', |
102
|
|
|
'is_active', |
103
|
|
|
]; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* {@inheritdoc} |
107
|
|
|
*/ |
108
|
|
|
protected $casts = [ |
109
|
|
|
'slug' => 'string', |
110
|
|
|
'owner_id' => 'integer', |
111
|
|
|
'owner_type' => 'string', |
112
|
|
|
'email' => 'string', |
113
|
|
|
'website' => 'string', |
114
|
|
|
'phone' => 'string', |
115
|
|
|
'country_code' => 'string', |
116
|
|
|
'language_code' => 'string', |
117
|
|
|
'state' => 'string', |
118
|
|
|
'city' => 'string', |
119
|
|
|
'address' => 'string', |
120
|
|
|
'postal_code' => 'string', |
121
|
|
|
'launch_date' => 'string', |
122
|
|
|
'timezone' => 'string', |
123
|
|
|
'currency' => 'string', |
124
|
|
|
'style' => 'string', |
125
|
|
|
'is_active' => 'boolean', |
126
|
|
|
'deleted_at' => 'datetime', |
127
|
|
|
]; |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Indicates whether to log only dirty attributes or all. |
131
|
|
|
* |
132
|
|
|
* @var bool |
133
|
|
|
*/ |
134
|
|
|
protected static $logOnlyDirty = true; |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* The attributes that are logged on change. |
138
|
|
|
* |
139
|
|
|
* @var array |
140
|
|
|
*/ |
141
|
|
|
protected static $logFillable = true; |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* The attributes that are ignored on change. |
145
|
|
|
* |
146
|
|
|
* @var array |
147
|
|
|
*/ |
148
|
|
|
protected static $ignoreChangedAttributes = [ |
149
|
|
|
'created_at', |
150
|
|
|
'updated_at', |
151
|
|
|
'deleted_at', |
152
|
|
|
]; |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Create a new Eloquent model instance. |
156
|
|
|
* |
157
|
|
|
* @param array $attributes |
158
|
|
|
*/ |
159
|
|
|
public function __construct(array $attributes = []) |
160
|
|
|
{ |
161
|
|
|
parent::__construct($attributes); |
162
|
|
|
|
163
|
|
|
$this->setTable(config('rinvex.tenants.tables.tenants')); |
164
|
|
|
$this->setRules([ |
165
|
|
|
'slug' => 'required|alpha_dash|max:150|unique:'.config('rinvex.tenants.tables.tenants').',slug', |
166
|
|
|
'name' => 'required|string|max:150', |
167
|
|
|
'description' => 'nullable|string|max:10000', |
168
|
|
|
'owner_id' => 'required|integer', |
169
|
|
|
'owner_type' => 'required|string', |
170
|
|
|
'email' => 'required|email|min:3|max:150|unique:'.config('rinvex.tenants.tables.tenants').',email', |
171
|
|
|
'website' => 'nullable|string|max:150', |
172
|
|
|
'phone' => 'required|phone:AUTO', |
173
|
|
|
'country_code' => 'required|alpha|size:2|country', |
174
|
|
|
'language_code' => 'required|alpha|size:2|language', |
175
|
|
|
'state' => 'nullable|string', |
176
|
|
|
'city' => 'nullable|string', |
177
|
|
|
'address' => 'nullable|string', |
178
|
|
|
'postal_code' => 'nullable|string', |
179
|
|
|
'launch_date' => 'nullable|date_format:Y-m-d', |
180
|
|
|
'timezone' => 'required|string|timezone', |
181
|
|
|
'currency' => 'required|string|size:3', |
182
|
|
|
'style' => 'nullable|string|max:150', |
183
|
|
|
'is_active' => 'sometimes|boolean', |
184
|
|
|
'tags' => 'nullable|array', |
185
|
|
|
]); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Register media collections. |
190
|
|
|
* |
191
|
|
|
* @return void |
192
|
|
|
*/ |
193
|
|
|
public function registerMediaCollections(): void |
194
|
|
|
{ |
195
|
|
|
$this->addMediaCollection('profile_picture')->singleFile(); |
196
|
|
|
$this->addMediaCollection('cover_photo')->singleFile(); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Get all attached managers to tenant. |
201
|
|
|
* |
202
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany |
203
|
|
|
*/ |
204
|
|
|
public function managers(): MorphToMany |
205
|
|
|
{ |
206
|
|
|
return $this->entries(config('cortex.auth.models.manager')); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* {@inheritdoc} |
211
|
|
|
*/ |
212
|
|
|
public function owner() |
213
|
|
|
{ |
214
|
|
|
return BelongsToMorph::build($this, Manager::class, 'owner'); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Get the route key for the model. |
219
|
|
|
* |
220
|
|
|
* @return string |
221
|
|
|
*/ |
222
|
|
|
public function getRouteKeyName() |
223
|
|
|
{ |
224
|
|
|
return 'slug'; |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
|
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.