ldc-boutique-cnc/app/Models/Site/GeneralConfig.php
2023-03-22 17:17:55 +01:00

88 lines
2 KiB
PHP

<?php
namespace App\Models\Site;
use App\Enums\GeneralConfigType;
use App\Traits\Models\IsCachedAsCollection;
use App\Traits\Models\MiniCrudModel;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use Kwaadpepper\Enum\Traits\CastsEnums;
/**
* GeneralConfig
*
* @property \App\Enums\GeneralConfigType $type The general type.
* @property object $data The general config data array.
*
* @package App\Models
*
*/
class GeneralConfig extends Model
{
use CastsEnums;
use MiniCrudModel;
use IsCachedAsCollection;
/**
* The primary key for the model.
*
* @var string
*/
protected $primaryKey = 'type';
/**
* Indicates if the IDs are auto-incrementing.
*
* @var boolean
*/
public $incrementing = false;
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'data' => 'object'
];
/**
* The attributes that should be cast to Enums.
*
* @var array
*/
protected $enumCasts = [
'type' => GeneralConfigType::class
];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'type', 'data'
];
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted()
{
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
static::created(function (self $config) {
Cache::delete('GeneralConfigGlobal');
});
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
static::updated(function (self $config) {
Cache::delete('GeneralConfigGlobal');
});
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
static::deleted(function (self $config) {
Cache::delete('GeneralConfigGlobal');
});
}
}