Просмотр файла app/Repositories/GuestbookRepository.php

Размер файла: 835B
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. namespace App\Repositories;
  6.  
  7. use App\Models\Guestbook;
  8. use MotorORM\CollectionPaginate;
  9.  
  10. class GuestbookRepository implements RepositoryInterface
  11. {
  12. /**
  13. * @param int $id
  14. *
  15. * @return Guestbook|null
  16. */
  17. public function getById(int $id): ?Guestbook
  18. {
  19. return Guestbook::query()->find($id);
  20. }
  21.  
  22. /**
  23. * Get count messages
  24. *
  25. * @return int
  26. */
  27. public function getCount(): int
  28. {
  29. return Guestbook::query()->count();
  30. }
  31.  
  32. /**
  33. * @param int $perPage
  34. *
  35. * @return CollectionPaginate<Guestbook>
  36. */
  37. public function getMessages(int $perPage): CollectionPaginate
  38. {
  39. return Guestbook::query()
  40. ->orderByDesc('created_at')
  41. ->with('user')
  42. ->paginate($perPage);
  43. }
  44. }