Просмотр файла app/Controllers/OnlineController.php

Размер файла: 1.57Kb
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. namespace App\Controllers;
  6.  
  7. use App\Models\Online;
  8. use Illuminate\Database\Query\JoinClause;
  9.  
  10. class OnlineController extends BaseController
  11. {
  12. /**
  13. * Главная страница
  14. *
  15. * @return string
  16. */
  17. public function index(): string
  18. {
  19. $guests = false;
  20.  
  21. $online = Online::query()
  22. ->select('o1.*')
  23. ->from('online as o1')
  24. ->leftJoin('online as o2', static function (JoinClause $join) {
  25. $join->on('o1.user_id', 'o2.user_id')
  26. ->on('o1.updated_at', '<', 'o2.updated_at');
  27. })
  28. ->whereNull('o2.updated_at')
  29. ->whereNotNull('o1.user_id')
  30. ->with('user')
  31. ->orderByDesc('updated_at')
  32. ->paginate(setting('onlinelist'));
  33.  
  34. return view('pages/online', compact('online', 'guests'));
  35. }
  36.  
  37. /**
  38. * Список всех пользователей
  39. *
  40. * @return string
  41. */
  42. public function all(): string
  43. {
  44. $guests = true;
  45.  
  46. $online = Online::query()
  47. ->select('o1.*')
  48. ->from('online as o1')
  49. ->leftJoin('online as o2', static function (JoinClause $join) {
  50. $join->on('o1.user_id', 'o2.user_id')
  51. ->on('o1.updated_at', '<', 'o2.updated_at');
  52. })
  53. ->whereNull('o2.updated_at')
  54. ->with('user')
  55. ->orderByDesc('updated_at')
  56. ->paginate(setting('onlinelist'));
  57.  
  58. return view('pages/online', compact('online', 'guests'));
  59. }
  60. }