1 | <?php |
||
69 | class Tenant extends Model |
||
70 | { |
||
71 | use HasSlug; |
||
72 | use HasTranslations; |
||
73 | use ValidatingTrait; |
||
74 | use CacheableEloquent; |
||
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | */ |
||
79 | protected $fillable = [ |
||
80 | 'slug', |
||
81 | 'name', |
||
82 | 'description', |
||
83 | 'owner_id', |
||
84 | 'owner_type', |
||
85 | 'email', |
||
86 | 'website', |
||
87 | 'phone', |
||
88 | 'language_code', |
||
89 | 'country_code', |
||
90 | 'state', |
||
91 | 'city', |
||
92 | 'address', |
||
93 | 'postal_code', |
||
94 | 'launch_date', |
||
95 | 'timezone', |
||
96 | 'currency', |
||
97 | 'is_active', |
||
98 | ]; |
||
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | protected $casts = [ |
||
104 | 'slug' => 'string', |
||
105 | 'owner_id' => 'integer', |
||
106 | 'owner_type' => 'string', |
||
107 | 'email' => 'string', |
||
108 | 'website' => 'string', |
||
109 | 'phone' => 'string', |
||
110 | 'country_code' => 'string', |
||
111 | 'language_code' => 'string', |
||
112 | 'state' => 'string', |
||
113 | 'city' => 'string', |
||
114 | 'address' => 'string', |
||
115 | 'postal_code' => 'string', |
||
116 | 'launch_date' => 'string', |
||
117 | 'timezone' => 'string', |
||
118 | 'currency' => 'string', |
||
119 | 'is_active' => 'boolean', |
||
120 | 'deleted_at' => 'datetime', |
||
121 | ]; |
||
122 | |||
123 | /** |
||
124 | * {@inheritdoc} |
||
125 | */ |
||
126 | protected $observables = [ |
||
127 | 'validating', |
||
128 | 'validated', |
||
129 | ]; |
||
130 | |||
131 | /** |
||
132 | * The attributes that are translatable. |
||
133 | * |
||
134 | * @var array |
||
135 | */ |
||
136 | public $translatable = [ |
||
137 | 'name', |
||
138 | 'description', |
||
139 | ]; |
||
140 | |||
141 | /** |
||
142 | * The default rules that the model will validate against. |
||
143 | * |
||
144 | * @var array |
||
145 | */ |
||
146 | protected $rules = []; |
||
147 | |||
148 | /** |
||
149 | * Whether the model should throw a |
||
150 | * ValidationException if it fails validation. |
||
151 | * |
||
152 | * @var bool |
||
153 | */ |
||
154 | protected $throwValidationExceptions = true; |
||
155 | |||
156 | /** |
||
157 | * Create a new Eloquent model instance. |
||
158 | * |
||
159 | * @param array $attributes |
||
160 | */ |
||
161 | public function __construct(array $attributes = []) |
||
187 | |||
188 | /** |
||
189 | * Get all attached models of the given class to the tenant. |
||
190 | * |
||
191 | * @param string $class |
||
192 | * |
||
193 | * @return \Illuminate\Database\Eloquent\Relations\MorphToMany |
||
194 | */ |
||
195 | public function entries(string $class): MorphToMany |
||
199 | |||
200 | /** |
||
201 | * Get the options for generating the slug. |
||
202 | * |
||
203 | * @return \Spatie\Sluggable\SlugOptions |
||
204 | */ |
||
205 | public function getSlugOptions(): SlugOptions |
||
212 | |||
213 | /** |
||
214 | * Get the tenant owner. |
||
215 | * |
||
216 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
217 | */ |
||
218 | public function owner() |
||
222 | |||
223 | /** |
||
224 | * Determine if the given model is owner of tenant. |
||
225 | * |
||
226 | * @param \Illuminate\Database\Eloquent\Model $model |
||
227 | * |
||
228 | * @return bool |
||
229 | */ |
||
230 | public function isOwner(Model $model): bool |
||
234 | |||
235 | /** |
||
236 | * Determine if the given model is staff of tenant. |
||
237 | * |
||
238 | * @param \Illuminate\Database\Eloquent\Model $model |
||
239 | * |
||
240 | * @return bool |
||
241 | */ |
||
242 | public function isStaff(Model $model): bool |
||
246 | |||
247 | /** |
||
248 | * Get tenants of the given owner. |
||
249 | * |
||
250 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
251 | * @param \Illuminate\Database\Eloquent\Model $owner |
||
252 | * |
||
253 | * @return \Illuminate\Database\Eloquent\Builder |
||
254 | */ |
||
255 | public function scopeOfOwner(Builder $builder, Model $owner): Builder |
||
259 | |||
260 | /** |
||
261 | * Activate the tenant. |
||
262 | * |
||
263 | * @return $this |
||
264 | */ |
||
265 | public function activate() |
||
271 | |||
272 | /** |
||
273 | * Deactivate the tenant. |
||
274 | * |
||
275 | * @return $this |
||
276 | */ |
||
277 | public function deactivate() |
||
283 | } |
||
284 |
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.