feat(boards): 게시글 파일 시스템 개선 및 이미지 미리보기 추가

- Morph map에 Post, Department 모델 등록 (ClassMorphViolationException 해결)
- 파일 저장 방식을 API 스타일로 변경 (document_id + document_type)
- 파일 미리보기 라우트 및 메서드 추가 (previewFile)
- 게시글 상세 페이지에서 이미지 첨부파일을 본문 상단에 풀 너비로 표시
- 비이미지 첨부파일은 하단에 다운로드 목록으로 분리

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-27 17:08:53 +09:00
parent 541b59173b
commit da159cc46e
7 changed files with 94 additions and 22 deletions

View File

@@ -257,7 +257,7 @@ public function uploadFiles(Post $post, array $files): array
// 파일 저장
Storage::disk('tenant')->put($filePath, file_get_contents($file));
// DB 레코드 생성
// DB 레코드 생성 (API 방식: document_id + document_type)
$fileRecord = File::create([
'tenant_id' => $tenantId,
'is_temp' => false,
@@ -269,8 +269,8 @@ public function uploadFiles(Post $post, array $files): array
'file_size' => $file->getSize(),
'mime_type' => $file->getMimeType(),
'file_type' => $this->getFileType($file->getMimeType()),
'fileable_type' => Post::class,
'fileable_id' => $post->id,
'document_type' => 'post',
'document_id' => $post->id,
'uploaded_by' => auth()->id(),
'created_by' => auth()->id(),
]);
@@ -381,4 +381,24 @@ public function downloadFile(Post $post, int $fileId)
return $file->download();
}
/**
* 파일 미리보기 (인라인 표시)
*/
public function previewFile(Post $post, int $fileId)
{
$file = $post->files()->find($fileId);
if (! $file) {
abort(404, '파일을 찾을 수 없습니다.');
}
if (! $file->existsInStorage()) {
abort(404, '파일을 찾을 수 없습니다.');
}
return response()->file($file->getStoragePath(), [
'Content-Type' => $file->mime_type,
]);
}
}