ldc-com-app-bo/app/Models/Setting.php

77 lines
2 KiB
PHP
Raw Normal View History

2023-04-17 17:46:20 +02:00
<?php
namespace App\Models;
use App\Enums\SettingTypesEnum;
use App\Lib\Helpers\FileStorageHelper;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
2025-05-20 16:20:23 +02:00
use Stancl\Tenancy\Database\Concerns\BelongsToTenant;
2023-04-17 17:46:20 +02:00
/**
* @property integer $id Settings id.
* @property string $key Settings key.
* @property string $value Settings value.
* @property \App\Enums\SettingTypesEnum $type Settings type.
* @property-read \Carbon\Carbon $created_at Created date.
* @property-read \Carbon\Carbon $updated_at Updated date.
2023-04-17 17:46:20 +02:00
*/
class Setting extends Model
{
2025-05-20 16:20:23 +02:00
use BelongsToTenant;
2023-04-17 17:46:20 +02:00
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var list<string>
2023-04-17 17:46:20 +02:00
*/
protected $fillable = [
'key',
'value',
'type',
'created_at',
'updated_at',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
2023-04-17 17:46:20 +02:00
*/
protected $casts = [
2023-04-17 17:46:20 +02:00
'type' => SettingTypesEnum::class
];
// * EVENTS
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted(): void
2023-04-17 17:46:20 +02:00
{
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');
}
});
}
}