77 lines
2.3 KiB
PHP
77 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Lib\Helpers\FileStorageHelper;
|
|
use App\Traits\Models\HasTranslations;
|
|
use App\Traits\Models\IsCachedAsCollection;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* @property string $sub_title Sous-titre de l'application'.
|
|
* @property string $footer_phrase Texte en bas de page.
|
|
* @property string $color HTML Color string.
|
|
* @property string $logo Logo path for the app.
|
|
* @property integer $items_by_line Items per line.
|
|
* @property integer $home_timeout Timeout time in seconds before returning to homepage.
|
|
* @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 HasTranslations;
|
|
use IsCachedAsCollection;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $fillable = [
|
|
'sub_title',
|
|
'footer_phrase',
|
|
'color',
|
|
'logo',
|
|
'items_by_line',
|
|
'home_timeout',
|
|
];
|
|
|
|
/**
|
|
* Translatable fields array
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
public $translatable = [
|
|
'sub_title',
|
|
'footer_phrase',
|
|
];
|
|
|
|
/**
|
|
* 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();
|
|
});
|
|
}
|
|
}
|