feat: harden tenant settings and import pipeline
This commit is contained in:
@@ -2,14 +2,12 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\EventPurchase;
|
||||
use App\Models\EventCreditsLedger;
|
||||
|
||||
class Tenant extends Model
|
||||
{
|
||||
@@ -17,14 +15,16 @@ class Tenant extends Model
|
||||
|
||||
protected $table = 'tenants';
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'settings' => 'array',
|
||||
'features' => 'array',
|
||||
'settings' => 'array',
|
||||
'last_activity_at' => 'datetime',
|
||||
'event_credits_balance' => 'integer',
|
||||
'subscription_tier' => 'string',
|
||||
'subscription_expires_at' => 'datetime',
|
||||
'total_revenue' => 'decimal:2',
|
||||
'settings_updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function events(): HasMany
|
||||
@@ -37,10 +37,10 @@ class Tenant extends Model
|
||||
return $this->hasManyThrough(
|
||||
Photo::class,
|
||||
Event::class,
|
||||
'tenant_id', // Foreign key on events table...
|
||||
'event_id', // Foreign key on photos table...
|
||||
'id', // Local key on tenants table...
|
||||
'id' // Local key on events table...
|
||||
'tenant_id',
|
||||
'event_id',
|
||||
'id',
|
||||
'id'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -59,6 +59,16 @@ class Tenant extends Model
|
||||
return $this->hasMany(EventCreditsLedger::class);
|
||||
}
|
||||
|
||||
public function setSettingsAttribute($value): void
|
||||
{
|
||||
if (is_string($value)) {
|
||||
$this->attributes['settings'] = $value;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->attributes['settings'] = json_encode($value ?? []);
|
||||
}
|
||||
|
||||
public function activeSubscription(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
|
||||
Reference in New Issue
Block a user