MessageController.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\Message;
  5. use Auth;
  6. class MessageController extends Controller
  7. {
  8. /**
  9. * Display a listing of the resource.
  10. *
  11. * @return \Illuminate\Http\Response
  12. */
  13. public function index()
  14. {
  15. //
  16. }
  17. /**
  18. * Show the form for creating a new resource.
  19. *
  20. * @return \Illuminate\Http\Response
  21. */
  22. public function create()
  23. {
  24. //
  25. }
  26. /**
  27. * Store a newly created resource in storage.
  28. *
  29. * @param \Illuminate\Http\Request $request
  30. * @return \Illuminate\Http\Response
  31. */
  32. public function store(Request $request)
  33. {
  34. $message = new Message;
  35. $message->conversation_id = $request->conversation_id;
  36. $message->user_id = Auth::user()->id;
  37. $message->message = $request->message;
  38. $message->save();
  39. $conversation = $message->conversation;
  40. if ($conversation->sender_id == Auth::user()->id) {
  41. $conversation->receiver_viewed ="1";
  42. }
  43. elseif($conversation->receiver_id == Auth::user()->id) {
  44. $conversation->sender_viewed ="1";
  45. }
  46. $conversation->save();
  47. return back();
  48. }
  49. /**
  50. * Display the specified resource.
  51. *
  52. * @param int $id
  53. * @return \Illuminate\Http\Response
  54. */
  55. public function show($id)
  56. {
  57. //
  58. }
  59. /**
  60. * Show the form for editing the specified resource.
  61. *
  62. * @param int $id
  63. * @return \Illuminate\Http\Response
  64. */
  65. public function edit($id)
  66. {
  67. //
  68. }
  69. /**
  70. * Update the specified resource in storage.
  71. *
  72. * @param \Illuminate\Http\Request $request
  73. * @param int $id
  74. * @return \Illuminate\Http\Response
  75. */
  76. public function update(Request $request, $id)
  77. {
  78. //
  79. }
  80. /**
  81. * Remove the specified resource from storage.
  82. *
  83. * @param int $id
  84. * @return \Illuminate\Http\Response
  85. */
  86. public function destroy($id)
  87. {
  88. //
  89. }
  90. }