1 | <?php |
||
71 | class Tenant extends Model |
||
72 | { |
||
73 | use HasSlug; |
||
74 | use HasTranslations; |
||
75 | use ValidatingTrait; |
||
76 | use CacheableEloquent; |
||
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 | 'timezone', |
||
98 | 'currency', |
||
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 | 'timezone' => 'string', |
||
120 | 'currency' => 'string', |
||
121 | 'is_active' => 'boolean', |
||
122 | 'deleted_at' => 'datetime', |
||
123 | ]; |
||
124 | |||
125 | /** |
||
126 | * {@inheritdoc} |
||
127 | */ |
||
128 | protected $observables = [ |
||
129 | 'validating', |
||
130 | 'validated', |
||
131 | ]; |
||
132 | |||
133 | /** |
||
134 | * The attributes that are translatable. |
||
135 | * |
||
136 | * @var array |
||
137 | */ |
||
138 | public $translatable = [ |
||
139 | 'name', |
||
140 | 'description', |
||
141 | ]; |
||
142 | |||
143 | /** |
||
144 | * The default rules that the model will validate against. |
||
145 | * |
||
146 | * @var array |
||
147 | */ |
||
148 | protected $rules = []; |
||
149 | |||
150 | /** |
||
151 | * Whether the model should throw a |
||
152 | * ValidationException if it fails validation. |
||
153 | * |
||
154 | * @var bool |
||
155 | */ |
||
156 | protected $throwValidationExceptions = true; |
||
157 | |||
158 | /** |
||
159 | * Create a new Eloquent model instance. |
||
160 | * |
||
161 | * @param array $attributes |
||
162 | */ |
||
163 | public function __construct(array $attributes = []) |
||
189 | |||
190 | /** |
||
191 | * Get all attached models of the given class to the tenant. |
||
192 | * |
||
193 | * @param string $class |
||
194 | * |
||
195 | * @return \Illuminate\Database\Eloquent\Relations\MorphToMany |
||
196 | */ |
||
197 | public function entries(string $class): MorphToMany |
||
201 | |||
202 | /** |
||
203 | * Get the options for generating the slug. |
||
204 | * |
||
205 | * @return \Spatie\Sluggable\SlugOptions |
||
206 | */ |
||
207 | public function getSlugOptions(): SlugOptions |
||
214 | |||
215 | /** |
||
216 | * Get the tenant's country. |
||
217 | * |
||
218 | * @return \Rinvex\Country\Country |
||
219 | */ |
||
220 | public function getCountryAttribute() |
||
224 | |||
225 | /** |
||
226 | * Get the tenant's language. |
||
227 | * |
||
228 | * @return \Rinvex\Language\Language |
||
229 | */ |
||
230 | public function getLanguageAttribute() |
||
234 | |||
235 | /** |
||
236 | * Get the tenant owner. |
||
237 | * |
||
238 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
239 | */ |
||
240 | public function owner() |
||
244 | |||
245 | /** |
||
246 | * Determine if the given model is owner of tenant. |
||
247 | * |
||
248 | * @param \Illuminate\Database\Eloquent\Model $model |
||
249 | * |
||
250 | * @return bool |
||
251 | */ |
||
252 | public function isOwner(Model $model): bool |
||
256 | |||
257 | /** |
||
258 | * Determine if the given model is staff of tenant. |
||
259 | * |
||
260 | * @param \Illuminate\Database\Eloquent\Model $model |
||
261 | * |
||
262 | * @return bool |
||
263 | */ |
||
264 | public function isStaff(Model $model): bool |
||
268 | |||
269 | /** |
||
270 | * Get tenants of the given owner. |
||
271 | * |
||
272 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
273 | * @param \Illuminate\Database\Eloquent\Model $owner |
||
274 | * |
||
275 | * @return \Illuminate\Database\Eloquent\Builder |
||
276 | */ |
||
277 | public function scopeOfOwner(Builder $builder, Model $owner): Builder |
||
281 | |||
282 | /** |
||
283 | * Activate the tenant. |
||
284 | * |
||
285 | * @return $this |
||
286 | */ |
||
287 | public function activate() |
||
293 | |||
294 | /** |
||
295 | * Deactivate the tenant. |
||
296 | * |
||
297 | * @return $this |
||
298 | */ |
||
299 | public function deactivate() |
||
305 | } |
||
306 |
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.