74 lines
1.7 KiB
PHP
74 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\SettingTypesEnum;
|
|
use App\Lib\Helpers\FileStorageHelper;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Kwaadpepper\Enum\Traits\CastsEnums;
|
|
|
|
/**
|
|
* @property integer $id
|
|
* @property string $key
|
|
* @property string $value
|
|
* @property SettingTypesEnum $type
|
|
* @property timestamp $created_at
|
|
* @property timestamp $updated_at
|
|
*/
|
|
class Setting extends Model
|
|
{
|
|
use HasFactory;
|
|
use CastsEnums;
|
|
|
|
/**
|
|
* fillable
|
|
* @var string[]
|
|
*/
|
|
protected $fillable = [
|
|
'key',
|
|
'value',
|
|
'type',
|
|
'created_at',
|
|
'updated_at',
|
|
];
|
|
|
|
/**
|
|
* cast enum
|
|
* @var string[]
|
|
*/
|
|
protected $enumCasts = [
|
|
'type' => SettingTypesEnum::class
|
|
];
|
|
|
|
// * EVENTS
|
|
|
|
/**
|
|
* Perform any actions required after the model boots.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected static function booted()
|
|
{
|
|
static::updating(function (self $model) {
|
|
if (
|
|
$model->key === "SquaredLogo" ||
|
|
$model->key === "RectangleLogo" ||
|
|
$model->key === "BackgroundImage" ||
|
|
$model->key === "HomeButtonImage"
|
|
) {
|
|
$model->value = FileStorageHelper::storeFile($model, $model->value, true);
|
|
}
|
|
});
|
|
static::deleted(function (self $model) {
|
|
if (
|
|
$model->key === "SquaredLogo" ||
|
|
$model->key === "RectangleLogo" ||
|
|
$model->key === "BackgroundImage" ||
|
|
$model->key === "HomeButtonImage"
|
|
) {
|
|
FileStorageHelper::removeFile($model, 'value');
|
|
}
|
|
});
|
|
}
|
|
}
|