*/ protected $fillable = [ 'type', 'data', 'created_at', 'updated_at' ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'type' => GeneralConfigType::class, 'data' => 'object', ]; /** * 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); } }