fixed errors in event and tenant resources
This commit is contained in:
@@ -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 ?? []);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user