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

Размер файла: 1Kb
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. namespace App\Repositories;
  6.  
  7. use App\Models\Comment;
  8. use MotorORM\Collection;
  9.  
  10. class CommentRepository implements RepositoryInterface
  11. {
  12. /**
  13. * @param int $id
  14. *
  15. * @return Comment|null
  16. */
  17. public function getById(int $id): ?Comment
  18. {
  19. return Comment::query()->find($id);
  20. }
  21.  
  22. /**
  23. * Get last comments
  24. *
  25. * @param int $count
  26. *
  27. * @return Collection<Comment>
  28. */
  29. public function getLastComments(int $count = 5): Collection
  30. {
  31. return Comment::query()
  32. ->orderByDesc('created_at')
  33. ->limit($count)
  34. ->with('story')
  35. ->get();
  36. }
  37.  
  38. /**
  39. * Get best comments
  40. *
  41. * @param int $count
  42. *
  43. * @return Collection<Comment>
  44. */
  45. public function getBestComments(int $count = 5): Collection
  46. {
  47. return Comment::query()
  48. ->orderByDesc('rating')
  49. ->limit($count)
  50. ->with('story')
  51. ->get();
  52. }
  53. }