PostsController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Post;
  4. use Illuminate\Http\Request;
  5. class PostsController extends Controller {
  6. /**
  7. * Show the form for creating a new resource.
  8. *
  9. * @return \Illuminate\Http\Response
  10. */
  11. public function create() {
  12. return view('posts.create');
  13. }
  14. /**
  15. * Remove the specified resource from storage.
  16. *
  17. * @param int $id
  18. *
  19. * @return \Illuminate\Http\Response
  20. */
  21. public function destroy($id) {
  22. //
  23. }
  24. /**
  25. * Show the form for editing the specified resource.
  26. *
  27. * @param int $id
  28. *
  29. * @return \Illuminate\Http\Response
  30. */
  31. public function edit($id) {
  32. //
  33. }
  34. /**
  35. * Display a listing of the resource.
  36. *
  37. * @return \Illuminate\Http\Response
  38. */
  39. public function index() {
  40. $posts = Post::all();
  41. return view('posts.index', compact('posts'));
  42. }
  43. public function show(Post $post) {
  44. return view('posts.show', compact('post'));
  45. }
  46. /**
  47. * Store a newly created resource in storage.
  48. *
  49. * - Create new post using the request data
  50. * - Save it to the database
  51. * - Redirect to the home page
  52. *
  53. * @param \Illuminate\Http\Request $request
  54. *
  55. * @return \Illuminate\Http\Response
  56. */
  57. public function store(Request $request) {
  58. // $post = new Post();
  59. // $post->title = $request->get('title');
  60. // $post->body = $request->get('body');
  61. // $post->save();
  62. Post::create([
  63. 'title' => $request->get('title'),
  64. 'body' => $request->get('body'),
  65. ]);
  66. return redirect('/');
  67. }
  68. /**
  69. * Update the specified resource in storage.
  70. *
  71. * @param \Illuminate\Http\Request $request
  72. * @param int $id
  73. *
  74. * @return \Illuminate\Http\Response
  75. */
  76. public function update(Request $request, $id) {
  77. //
  78. }
  79. }