first(); if (!$config) { return $default; } return match ($config->type) { 'integer' => (int) $config->value, 'boolean' => (bool) $config->value, 'json' => json_decode($config->value, true), default => $config->value, }; } /** * 주어진 키에 시스템 설정 값을 저장합니다. * * @param string $key 설정 키 * @param mixed $value 저장할 값 * @param string $type 값의 타입 (기본값: 'string') * @param string|null $module 모듈명 (선택사항) * @return void */ public static function set(string $key, $value, string $type = 'string', ?string $module = null): void { $processedValue = match ($type) { 'json' => json_encode($value), default => (string) $value, }; static::updateOrCreate( ['key' => $key], [ 'value' => $processedValue, 'type' => $type, 'module' => $module, ] ); } /** * 첨부파일 다형성 관계 * * @param string|null $collection 컬렉션명 (선택) * @return MorphMany */ public function attachments(?string $collection = null): MorphMany { $relation = $this->morphMany(Attachment::class, 'attachmentable'); if ($collection) { $relation->where('collection', $collection); } return $relation; } }