Initial commit: CABM-IT (ItGlue-style MSP documentation platform)
Laravel 13 + Livewire/Volt app for managing client organizations, documents, passwords, flexible assets, virtual machines, contacts, domains, todos, shortcuts, and role-based user administration.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
#[Fillable(['organization_id', 'name', 'registrar', 'nameservers', 'expires_at', 'auto_renew', 'last_checked_at', 'notes'])]
|
||||
class Domain extends Model
|
||||
{
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'expires_at' => 'date',
|
||||
'auto_renew' => 'boolean',
|
||||
'last_checked_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function organization()
|
||||
{
|
||||
return $this->belongsTo(Organization::class);
|
||||
}
|
||||
|
||||
public function sslCertificates()
|
||||
{
|
||||
return $this->hasMany(SslCertificate::class);
|
||||
}
|
||||
|
||||
public function tld(): ?string
|
||||
{
|
||||
$parts = explode('.', $this->name);
|
||||
|
||||
return count($parts) > 1 ? '.'.end($parts) : null;
|
||||
}
|
||||
|
||||
public function expiresInDays(): ?int
|
||||
{
|
||||
return $this->expires_at ? now()->startOfDay()->diffInDays($this->expires_at, false) : null;
|
||||
}
|
||||
|
||||
public function expiryStatus(): string
|
||||
{
|
||||
$days = $this->expiresInDays();
|
||||
|
||||
return match (true) {
|
||||
$days === null => 'unknown',
|
||||
$days < 0 => 'expired',
|
||||
$days <= 30 => 'soon',
|
||||
default => 'ok',
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user