Add tenant lifecycle view and limit controls
This commit is contained in:
@@ -31,8 +31,11 @@ class Tenant extends Model
|
||||
'total_revenue' => 'decimal:2',
|
||||
'settings_updated_at' => 'datetime',
|
||||
'subscription_expires_at' => 'datetime',
|
||||
'grace_period_ends_at' => 'datetime',
|
||||
'credit_warning_sent_at' => 'datetime',
|
||||
'credit_warning_threshold' => 'integer',
|
||||
'max_photos_per_event' => 'integer',
|
||||
'max_storage_mb' => 'integer',
|
||||
];
|
||||
|
||||
public function events(): HasMany
|
||||
@@ -84,6 +87,11 @@ class Tenant extends Model
|
||||
return $this->hasMany(TenantNotificationLog::class);
|
||||
}
|
||||
|
||||
public function lifecycleEvents(): HasMany
|
||||
{
|
||||
return $this->hasMany(TenantLifecycleEvent::class);
|
||||
}
|
||||
|
||||
public function canCreateEvent(): bool
|
||||
{
|
||||
return $this->hasEventAllowance();
|
||||
@@ -174,4 +182,20 @@ class Tenant extends Model
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function getStorageQuotaAttribute(): int
|
||||
{
|
||||
$limitMb = (int) ($this->max_storage_mb ?? 0);
|
||||
|
||||
return max(0, $limitMb) * 1024 * 1024;
|
||||
}
|
||||
|
||||
public function isInGracePeriod(): bool
|
||||
{
|
||||
if (! $this->grace_period_ends_at) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return now()->lessThanOrEqualTo($this->grace_period_ends_at);
|
||||
}
|
||||
}
|
||||
|
||||
29
app/Models/TenantLifecycleEvent.php
Normal file
29
app/Models/TenantLifecycleEvent.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class TenantLifecycleEvent extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'payload' => 'array',
|
||||
'occurred_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function tenant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Tenant::class);
|
||||
}
|
||||
|
||||
public function actor(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'actor_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user