보안 best practice #173
김철수
2026-05-28 08:23
56
CLI 명령어로 생성된 샘플 게시물입니다.
소스
상세 조회 + 조회수 증가
public function show(int $id): string
{
$post = $this->model->find($id);
if (! $post) {
throw PageNotFoundException::forPageNotFound();
}
// 조회수 +1 (raw expression 사용)
$this->model->incrementViews($id);
return view('examples/board/show', ['post' => $post]);
}
// PostModel의 메서드
public function incrementViews(int $id): void
{
$this->set('views', 'views + 1', false)->where('id', $id)->update();
}