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