'array', 'is_system_company' => 'boolean', ]; protected static function booted(): void { static::creating(function (Company $company): void { $company->uuid ??= (string) Str::uuid(); $company->slug ??= Str::slug($company->name); $company->status ??= 'active'; $company->timezone ??= 'Europe/London'; }); } public function country(): BelongsTo { return $this->belongsTo(Country::class); } public function address(): MorphOne { return $this->morphOne(CompanyAddress::class, 'addressable'); } public function divisions(): HasMany { return $this->hasMany(CompanyDivision::class); } public function directorAssignments(): HasMany { return $this->hasMany(CompanyDirectorAssignment::class); } public function users(): HasMany { return $this->hasMany(User::class); } public function licenseKeys(): HasMany { return $this->hasMany(LicenseKey::class); } public function payments(): HasMany { return $this->hasMany(Payment::class); } public function warehouses(): HasMany { return $this->hasMany(Warehouse::class); } public function hasActiveLicense(): bool { if ($this->is_system_company) { return true; } return $this->licenseKeys() ->where('is_active', true) ->where(function ($query): void { $query->whereNull('starts_at')->orWhere('starts_at', '<=', now()); }) ->where(function ($query): void { $query->whereNull('expires_at')->orWhere('expires_at', '>=', now()); }) ->whereNull('revoked_at') ->exists(); } }