라라벨/게시판만들기
게시판 만들기3 -글보기 페이지만들기-
땀모
2019. 5. 9. 06:36
게시판 목록에서 글을 클릭했을 때 자세히 보기를 구현하겠다.
web.php에서 라우터설정을 해준다.
1 | Route::post('/posts/{post}','PostsController@show'); | cs |
resources/views/posts/show.blade.php 파일에 글제목에다가 해당 글의 링크를 걸어준다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <!DOCTYPE html> <html> <head> <title></title> </head> <body> <h1>게시판 목록</h1> <ul> @foreach($posts as $post) <li> <a href="/posts/{{$post->id}}"> {{ $post->title }} </a> </li> @endforeach </ul> <form method="get" action="/posts/create"> <button type="submit"> 글 작성하기 </button> </form> </body> </html> | cs |
PostsController.php show() 메서드에서 다음과 같이 작성해주자
1 2 3 4 | public function show(Post $post) { return view('posts.show',compact('post')); } | cs |
resources/views/posts/show.blade.php 파일을 생성하고 소스를 작성한다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <!DOCTYPE html> <html> <head> <title></title> </head> <body> <h1>글 상세페이지</h1> <div> {{ $post->title }} </div> <div> {{ $post->description }} </div> <div> <a href="/posts/{{ $post->id }}/edit">수정하기</a> </div> </body> </html> | cs |