'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 (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'); }); } /** * Get from cached all configs * * @return \Illuminate\Database\Eloquent\Collection */ public static function getCachedConfigs(): 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); } }