ldc-showroom-bo/app/Models/Settings.php
2024-01-05 17:36:16 +01:00

61 lines
1.8 KiB
PHP

<?php
namespace App\Models;
use App\Lib\Helpers\FileStorageHelper;
use App\Traits\Models\IsCachedAsCollection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* @property string $title App title.
* @property string $color HTML Color string.
* @property string $logo Logo path for the app.
* @property integer $items_by_line Items per line.
* @property-read \Illuminate\Support\Carbon $created_at Created date.
* @property-read \Illuminate\Support\Carbon $updated_at Updated date.
*
*/
class Settings extends Model
{
use HasFactory;
use IsCachedAsCollection;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'title',
'color',
'logo',
'items_by_line',
];
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted(): void
{
static::creating(function (self $model) {
// * TRANSFORMATIONS
$model->logo = FileStorageHelper::storeFile($model, $model->logo, true);
});
static::created(fn () => self::removeCached());
static::updating(function (self $model) {
// * TRANSFORMATIONS
$model->logo = FileStorageHelper::storeFile($model, $model->logo, true);
});
static::updated(function (self $model) {
FileStorageHelper::removeOldFile($model, 'logo');
self::removeCached();
});
static::deleted(function (self $model) {
FileStorageHelper::removeFile($model, 'logo');
self::removeCached();
});
}
}