2021-09-20 16:19:42 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use App\Enums\GeneralConfigType;
|
|
|
|
|
use App\Traits\MiniCrudModel;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2021-09-20 23:23:46 +02:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2021-09-20 16:19:42 +02:00
|
|
|
use Kwaadpepper\Enum\Traits\CastsEnums;
|
|
|
|
|
|
|
|
|
|
class GeneralConfig extends Model
|
|
|
|
|
{
|
|
|
|
|
use CastsEnums;
|
|
|
|
|
use MiniCrudModel;
|
|
|
|
|
|
|
|
|
|
protected $enumCasts = [
|
|
|
|
|
'type' => GeneralConfigType::class
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'data' => 'array'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $primaryKey = 'type';
|
|
|
|
|
|
|
|
|
|
public $incrementing = false;
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'type', 'data'
|
|
|
|
|
];
|
2021-09-20 23:23:46 +02:00
|
|
|
|
|
|
|
|
protected static function booted()
|
|
|
|
|
{
|
|
|
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
|
|
|
|
static::created(function (GeneralConfig $config) {
|
|
|
|
|
Cache::delete('GeneralConfigGlobal');
|
|
|
|
|
});
|
|
|
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
|
|
|
|
static::updated(function (GeneralConfig $config) {
|
|
|
|
|
Cache::delete('GeneralConfigGlobal');
|
|
|
|
|
});
|
|
|
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
|
|
|
|
static::deleted(function (GeneralConfig $config) {
|
|
|
|
|
Cache::delete('GeneralConfigGlobal');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getCachedConfigs()
|
|
|
|
|
{
|
|
|
|
|
if (!Cache::has('GeneralConfigGlobal')) {
|
|
|
|
|
self::setCachedConfigs();
|
|
|
|
|
}
|
|
|
|
|
return Cache::get('GeneralConfigGlobal');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static function setCachedConfigs()
|
|
|
|
|
{
|
|
|
|
|
$configs = GeneralConfig::all();
|
|
|
|
|
Cache::put('GeneralConfigGlobal', $configs);
|
|
|
|
|
}
|
2021-09-20 16:19:42 +02:00
|
|
|
}
|