1 | <?php |
||
65 | class Tenant extends Model |
||
66 | { |
||
67 | use HasSlug; |
||
68 | use HasTranslations; |
||
69 | use ValidatingTrait; |
||
70 | use CacheableEloquent; |
||
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | protected $fillable = [ |
||
76 | 'slug', |
||
77 | 'name', |
||
78 | 'description', |
||
79 | 'owner_id', |
||
80 | 'owner_type', |
||
81 | 'email', |
||
82 | 'website', |
||
83 | 'phone', |
||
84 | 'language_code', |
||
85 | 'country_code', |
||
86 | 'state', |
||
87 | 'city', |
||
88 | 'address', |
||
89 | 'postal_code', |
||
90 | 'launch_date', |
||
91 | 'group', |
||
92 | 'is_active', |
||
93 | ]; |
||
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | protected $casts = [ |
||
99 | 'slug' => 'string', |
||
100 | 'owner_id' => 'integer', |
||
101 | 'owner_type' => 'string', |
||
102 | 'email' => 'string', |
||
103 | 'website' => 'string', |
||
104 | 'phone' => 'string', |
||
105 | 'country_code' => 'string', |
||
106 | 'language_code' => 'string', |
||
107 | 'state' => 'string', |
||
108 | 'city' => 'string', |
||
109 | 'address' => 'string', |
||
110 | 'postal_code' => 'string', |
||
111 | 'launch_date' => 'string', |
||
112 | 'group' => 'string', |
||
113 | 'is_active' => 'boolean', |
||
114 | 'deleted_at' => 'datetime', |
||
115 | ]; |
||
116 | |||
117 | /** |
||
118 | * {@inheritdoc} |
||
119 | */ |
||
120 | protected $observables = [ |
||
121 | 'validating', |
||
122 | 'validated', |
||
123 | ]; |
||
124 | |||
125 | /** |
||
126 | * The attributes that are translatable. |
||
127 | * |
||
128 | * @var array |
||
129 | */ |
||
130 | public $translatable = [ |
||
131 | 'name', |
||
132 | 'description', |
||
133 | ]; |
||
134 | |||
135 | /** |
||
136 | * The default rules that the model will validate against. |
||
137 | * |
||
138 | * @var array |
||
139 | */ |
||
140 | protected $rules = []; |
||
141 | |||
142 | /** |
||
143 | * Whether the model should throw a |
||
144 | * ValidationException if it fails validation. |
||
145 | * |
||
146 | * @var bool |
||
147 | */ |
||
148 | protected $throwValidationExceptions = true; |
||
149 | |||
150 | /** |
||
151 | * Create a new Eloquent model instance. |
||
152 | * |
||
153 | * @param array $attributes |
||
154 | */ |
||
155 | public function __construct(array $attributes = []) |
||
180 | |||
181 | /** |
||
182 | * Get all attached models of the given class to the tenant. |
||
183 | * |
||
184 | * @param string $class |
||
185 | * |
||
186 | * @return \Illuminate\Database\Eloquent\Relations\MorphToMany |
||
187 | */ |
||
188 | public function entries(string $class): MorphToMany |
||
192 | |||
193 | /** |
||
194 | * Get the options for generating the slug. |
||
195 | * |
||
196 | * @return \Spatie\Sluggable\SlugOptions |
||
197 | */ |
||
198 | public function getSlugOptions(): SlugOptions |
||
205 | |||
206 | /** |
||
207 | * Get the tenant owner. |
||
208 | * |
||
209 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
210 | */ |
||
211 | public function owner() |
||
215 | |||
216 | /** |
||
217 | * Determine if the given model is owner of tenant. |
||
218 | * |
||
219 | * @param \Illuminate\Database\Eloquent\Model $model |
||
220 | * |
||
221 | * @return bool |
||
222 | */ |
||
223 | public function isOwner(Model $model): bool |
||
227 | |||
228 | /** |
||
229 | * Determine if the given model is staff of tenant. |
||
230 | * |
||
231 | * @param \Illuminate\Database\Eloquent\Model $model |
||
232 | * |
||
233 | * @return bool |
||
234 | */ |
||
235 | public function isStaff(Model $model): bool |
||
239 | |||
240 | /** |
||
241 | * Get tenants of the given owner. |
||
242 | * |
||
243 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
244 | * @param \Illuminate\Database\Eloquent\Model $owner |
||
245 | * |
||
246 | * @return \Illuminate\Database\Eloquent\Builder |
||
247 | */ |
||
248 | public function scopeOfOwner(Builder $builder, Model $owner): Builder |
||
252 | |||
253 | /** |
||
254 | * Activate the tenant. |
||
255 | * |
||
256 | * @return $this |
||
257 | */ |
||
258 | public function makeActive() |
||
264 | |||
265 | /** |
||
266 | * Deactivate the tenant. |
||
267 | * |
||
268 | * @return $this |
||
269 | */ |
||
270 | public function makeInactive() |
||
276 | } |
||
277 |
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.