2024-01-31 17:25:01 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use App\Enums\GeneralConfigType;
|
2024-02-01 10:19:11 +01:00
|
|
|
use App\Traits\Models\ActivityLog;
|
2024-01-31 17:25:01 +01:00
|
|
|
use App\Traits\Models\MiniCrudModel;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
|
|
|
|
|
|
class GeneralConfig extends Model
|
|
|
|
|
{
|
2024-02-01 10:19:11 +01:00
|
|
|
use ActivityLog;
|
2024-01-31 17:25:01 +01:00
|
|
|
use MiniCrudModel;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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 are mass assignable.
|
|
|
|
|
*
|
2024-08-30 11:32:50 +02:00
|
|
|
* @var array<int, string>
|
2024-01-31 17:25:01 +01:00
|
|
|
*/
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'type',
|
2024-02-01 10:19:11 +01:00
|
|
|
'data',
|
|
|
|
|
'created_at',
|
|
|
|
|
'updated_at'
|
2024-01-31 17:25:01 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that should be cast.
|
|
|
|
|
*
|
|
|
|
|
* @var array<string, string>
|
|
|
|
|
*/
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'type' => GeneralConfigType::class,
|
2024-02-01 10:19:11 +01:00
|
|
|
'data' => 'object',
|
2024-01-31 17:25:01 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Perform any actions required after the model boots.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected static function booted()
|
|
|
|
|
{
|
|
|
|
|
static::created(function () {
|
|
|
|
|
Cache::delete('GeneralConfigGlobal');
|
|
|
|
|
});
|
|
|
|
|
static::updated(function () {
|
|
|
|
|
Cache::delete('GeneralConfigGlobal');
|
|
|
|
|
});
|
|
|
|
|
static::deleted(function () {
|
|
|
|
|
Cache::delete('GeneralConfigGlobal');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get from cached all configs
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Collection
|
|
|
|
|
*/
|
|
|
|
|
public static function getCachedConfigs(): \Illuminate\Database\Eloquent\Collection
|
|
|
|
|
{
|
|
|
|
|
if (!Cache::has('GeneralConfigGlobal')) {
|
|
|
|
|
self::setCachedConfigs();
|
|
|
|
|
}
|
|
|
|
|
return Cache::get('GeneralConfigGlobal');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Put in cache all configs
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected static function setCachedConfigs()
|
|
|
|
|
{
|
|
|
|
|
$configs = GeneralConfig::all();
|
|
|
|
|
Cache::put('GeneralConfigGlobal', $configs);
|
|
|
|
|
}
|
|
|
|
|
}
|