66 lines
1.3 KiB
PHP
66 lines
1.3 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
|
|
use Carbon\Carbon;
|
||
|
|
|
||
|
|
class Domain extends Model
|
||
|
|
{
|
||
|
|
protected $fillable = [
|
||
|
|
'site_id',
|
||
|
|
'domain',
|
||
|
|
'expires_at',
|
||
|
|
'last_checked_at',
|
||
|
|
'is_active',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $casts = [
|
||
|
|
'expires_at' => 'datetime',
|
||
|
|
'last_checked_at' => 'datetime',
|
||
|
|
'is_active' => 'boolean',
|
||
|
|
];
|
||
|
|
|
||
|
|
public function site(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Site::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Check if domain is expiring soon (within 30 days)
|
||
|
|
*/
|
||
|
|
public function isExpiringSoon(): bool
|
||
|
|
{
|
||
|
|
if (!$this->expires_at) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
return $this->expires_at->lte(Carbon::now()->addDays(30));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Check if domain has expired
|
||
|
|
*/
|
||
|
|
public function isExpired(): bool
|
||
|
|
{
|
||
|
|
if (!$this->expires_at) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
return $this->expires_at->lte(Carbon::now());
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get days until expiration
|
||
|
|
*/
|
||
|
|
public function daysUntilExpiration(): ?int
|
||
|
|
{
|
||
|
|
if (!$this->expires_at) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
return Carbon::now()->diffInDays($this->expires_at, false);
|
||
|
|
}
|
||
|
|
}
|