|WebsiteSetting where($column, $operator = null, $value = null) * @method static \Illuminate\Database\Eloquent\Builder|WebsiteSetting whereIn(string $column, array $values) * @method static \Illuminate\Database\Eloquent\Builder|WebsiteSetting whereNotIn(string $column, array $values) * @method static \Illuminate\Database\Eloquent\Builder|WebsiteSetting orWhere($column, $operator = null, $value = null) * @method static \Illuminate\Database\Eloquent\Builder|WebsiteSetting count($columns = '*') * @method static \Illuminate\Database\Eloquent\Builder|WebsiteSetting get($columns = ['*']) * @method static \Illuminate\Database\Eloquent\Builder|WebsiteSetting first() * @method static \Illuminate\Database\Eloquent\Builder|WebsiteSetting updateOrCreate(array $attributes, array $values = []) * @method static \Illuminate\Database\Eloquent\Builder|WebsiteSetting pluck($column, $key = null) * @method static \Illuminate\Database\Eloquent\Builder|WebsiteSetting exists() * * @property string $key * @property string|null $value */ class WebsiteSetting extends Model { use HasFactory; protected static function newFactory() { return WebsiteSettingFactory::new(); } #[\Override] protected $guarded = ['id']; public static function updateOrCreate(array $attributes, array $values = []): Builder|Model { $instance = static::firstOrNew($attributes); if (! $instance->getKey()) { $instance->forceFill(array_merge($attributes, $values))->save(); } else { $instance->fill($values)->save(); } return $instance; } public static function firstOrCreate(array $attributes, array $values = []): Model|static { $instance = static::firstOrNew($attributes); if (! $instance->getKey()) { $instance->forceFill(array_merge($attributes, $values))->save(); } return $instance; } #[\Override] public $timestamps = false; #[\Override] protected static function booted(): void { static::saved(function (WebsiteSetting $setting) { SettingsService::clearCache(); self::clearRelatedCache($setting->key); }); static::deleted(function (WebsiteSetting $setting) { SettingsService::clearCache(); self::clearRelatedCache($setting->key); }); } private static function clearRelatedCache(?string $key): void { if ($key === null) { CacheService::clearAllAppCache(); return; } if (str_starts_with($key, 'points_')) { CacheService::clearPointsSettings(); CacheService::clearLeaderboards(); CacheService::clearApiCache(); return; } if (str_starts_with($key, 'ai_filter_') || str_starts_with($key, 'filter_word_')) { CacheService::clearContentModeration(); return; } if (str_starts_with($key, 'radio_')) { CacheService::clearRadioSettings(); CacheService::clearLeaderboards(); CacheService::clearApiCache(); CacheService::clearLeaderboard(); return; } if (str_starts_with($key, 'rare_value_')) { CacheService::clearRareValueCategories(); return; } if (str_starts_with($key, 'staff_')) { CacheService::clearStaff(); CacheService::clearLeaderboard(); return; } if (str_starts_with($key, 'help_center') || str_starts_with($key, 'website_rules')) { CacheService::clearHelpCenter(); return; } } }