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