DirectMessageController.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Auth;
  4. use Illuminate\Http\Request;
  5. use App\{
  6. DirectMessage,
  7. Profile,
  8. Status
  9. };
  10. class DirectMessageController extends Controller
  11. {
  12. public function __construct()
  13. {
  14. $this->middleware('auth');
  15. }
  16. public function inbox(Request $request)
  17. {
  18. $profile = Auth::user()->profile;
  19. $inbox = DirectMessage::selectRaw('*, max(created_at) as createdAt')
  20. ->whereToId($profile->id)
  21. ->with(['author','status'])
  22. ->orderBy('createdAt', 'desc')
  23. ->groupBy('from_id')
  24. ->paginate(12);
  25. return view('account.messages', compact('inbox'));
  26. }
  27. public function show(Request $request, int $pid, $mid)
  28. {
  29. $profile = Auth::user()->profile;
  30. if($pid !== $profile->id) {
  31. abort(403);
  32. }
  33. $msg = DirectMessage::whereToId($profile->id)
  34. ->findOrFail($mid);
  35. $thread = DirectMessage::whereIn('to_id', [$profile->id, $msg->from_id])
  36. ->whereIn('from_id', [$profile->id,$msg->from_id])
  37. ->orderBy('created_at', 'desc')
  38. ->paginate(30);
  39. $thread = $thread->reverse();
  40. return view('account.message', compact('msg', 'profile', 'thread'));
  41. }
  42. public function compose(Request $request)
  43. {
  44. $profile = Auth::user()->profile;
  45. }
  46. }