CommentController.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\Input;
  5. use App\Comment;
  6. use App\Post;
  7. class CommentController extends Controller
  8. {
  9. /**
  10. * Display a listing of the resource.
  11. *
  12. * @return \Illuminate\Http\Response
  13. */
  14. public function index()
  15. {
  16. //
  17. }
  18. /**
  19. * Show the form for creating a new resource.
  20. *
  21. * @return \Illuminate\Http\Response
  22. */
  23. public function create()
  24. {
  25. //
  26. }
  27. /**
  28. * Store a newly created resource in storage.
  29. *
  30. * @param \Illuminate\Http\Request $request
  31. * @return \Illuminate\Http\Response
  32. */
  33. public function store(Request $request)
  34. {
  35. $newRecord = new Comment([ 'text' =>Input::get('text')]);
  36. $post = Post::find(Input::get('post_id'));
  37. //$newRecord->post()->associate($post);
  38. //$newRecord->save();
  39. $post->comments()->save($newRecord);
  40. //$newRecord = new Comment([ 'text' =>Input::get('text'),
  41. //'post_id' => Input::get('post_id')]);
  42. //$newRecord->save();
  43. return redirect(route('cntrl.show', [Input::get('post_id')]));
  44. }
  45. /**
  46. * Display the specified resource.
  47. *
  48. * @param int $id
  49. * @return \Illuminate\Http\Response
  50. */
  51. public function show($id)
  52. {
  53. //
  54. }
  55. /**
  56. * Show the form for editing the specified resource.
  57. *
  58. * @param int $id
  59. * @return \Illuminate\Http\Response
  60. */
  61. public function edit($id)
  62. {
  63. //
  64. }
  65. /**
  66. * Update the specified resource in storage.
  67. *
  68. * @param \Illuminate\Http\Request $request
  69. * @param int $id
  70. * @return \Illuminate\Http\Response
  71. */
  72. public function update(Request $request, $id)
  73. {
  74. //
  75. }
  76. /**
  77. * Remove the specified resource from storage.
  78. *
  79. * @param int $id
  80. * @return \Illuminate\Http\Response
  81. */
  82. public function destroy($id)
  83. {
  84. //
  85. }
  86. }