diff --git a/app/Models/Settings.php b/app/Models/Settings.php index 672c46f..19fa538 100644 --- a/app/Models/Settings.php +++ b/app/Models/Settings.php @@ -65,21 +65,13 @@ class Settings extends Model protected static function booted(): void { static::creating(function (self $model) { - // * TRANSFORMATIONS - /** @phpstan-ignore-next-line */ - if ($model->logo instanceof UploadedFile) { - $model->logo = ShowroomFileHelper::storeFileWithUUIDName($model->logo, $model); - } + self::manageFields($model); }); static::created(function (self $model) { self::resetCache($model->tenant_id); }); static::updating(function (self $model) { - // * TRANSFORMATIONS - /** @phpstan-ignore-next-line */ - if ($model->logo instanceof UploadedFile) { - $model->logo = ShowroomFileHelper::storeFileWithUUIDName($model->logo, $model); - } + self::manageFields($model); }); static::updated(function (self $model) { FileHelper::removeOldFile($model, 'logo'); @@ -93,6 +85,24 @@ class Settings extends Model // * METHODS + /** + * Common methods function. + * + * @param self $model + * @return void + */ + private static function manageFields(self $model) + { + // * TRANSFORMATIONS + /** @phpstan-ignore-next-line */ + if ($model->logo instanceof UploadedFile) { + $model->logo = ShowroomFileHelper::storeFileWithUUIDName($model->logo, $model); + } + if (!$model->locales) { + $model->locales = []; + } + } + /** * Get from cache a Setting model with a key like this : {tenant}_settings and for remember it 24 hours. *