fixed errors in event and tenant resources

This commit is contained in:
Codex Agent
2025-10-15 21:43:24 +02:00
parent 1a4bdb1fe1
commit 58d9ef34ab
8 changed files with 116 additions and 106 deletions

View File

@@ -16,7 +16,6 @@ class Event extends Model
protected $guarded = [];
protected $casts = [
'date' => 'datetime',
'settings' => 'array',
'is_active' => 'boolean',
'name' => 'array',
'description' => 'array',
@@ -58,6 +57,11 @@ class Event extends Model
return $this->belongsTo(EventPackage::class);
}
public function eventPackages(): HasMany
{
return $this->hasMany(EventPackage::class);
}
public function joinTokens(): HasMany
{
return $this->hasMany(EventJoinToken::class);
@@ -85,4 +89,29 @@ class Event extends Model
return $this->eventPackage->canUploadPhoto();
}
public function getSettingsAttribute($value): array
{
if (is_array($value)) {
return $value;
}
if (is_string($value) && $value !== '') {
$decoded = json_decode($value, true);
return is_array($decoded) ? $decoded : [];
}
return [];
}
public function setSettingsAttribute($value): void
{
if (is_string($value)) {
$decoded = json_decode($value, true);
$value = is_array($decoded) ? $decoded : [];
}
$this->attributes['settings'] = json_encode($value ?? []);
}
}