'json', ]; public function user(): BelongsTo { return $this->belongsTo(User::class); } public static function getForUser(int $userId, string $key, mixed $default = null): mixed { return Cache::remember("user_setting.{$userId}.{$key}", 3600, function () use ($userId, $key, $default) { return static::query() ->where('user_id', $userId) ->where('key', $key) ->value('value') ?? $default; }); } public static function setForUser(int $userId, string $key, mixed $value): void { static::updateOrCreate( ['user_id' => $userId, 'key' => $key], ['value' => $value] ); Cache::forget("user_setting.{$userId}.{$key}"); } public static function forgetForUser(int $userId, string $key): void { static::query() ->where('user_id', $userId) ->where('key', $key) ->delete(); Cache::forget("user_setting.{$userId}.{$key}"); } public static function getAllForUser(int $userId): array { return static::query() ->where('user_id', $userId) ->pluck('value', 'key') ->toArray(); } }