route('code'); $postID = $request->route('postID'); $commentID = $request->input('cid'); $mode = $request->input('mode'); // 게시판 코드 확인 if (!$code || !$postID) { throw new Exception('잘못된 접근입니다.', 404); } $boardService = new BoardService(); // 게시판 정보 조회 $board = $boardService->find($code); // 게시판 존재 유무 if (!$board->exists) { throw new Exception('존재하지 않는 게시판입니다.'); } // 게시판 사용 여부 if ($board->is_display == 0) { throw new Exception('더 이상 사용하지 않는 게시판입니다.'); } $postService = new PostService(); // 게시글 조회 $post = $postService->postModel->isExists($postID); if(!$post) { throw new Exception('존재하지 않는 게시글입니다.'); } // 댓글 조회 if($commentID && $mode == 'reply') { // 답글 작성 시 확인 $commentService = new CommentService(); $comment = $commentService->find($commentID); if(!$comment->exists) { throw new Exception('존재하지 않는 댓글입니다.'); } } // 게시판 정보 조회 $boardMeta = $boardService->meta($board->id); // 댓글 쓰기 권한 확인 $response = Gate::inspect('create', ['App\Models\Comment', $boardMeta]); if($response->denied()) { throw new Exception($response->message(), $response->code()); } $request->merge([ 'board' => $board, 'boardMeta' => $boardMeta ]); }catch(Exception $e) { return ResponseData::fromException($e); } return $next($request); } }