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

Размер файла: 718B
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. namespace App\Repositories;
  6.  
  7. use App\Models\Favorite;
  8. use MotorORM\Collection;
  9.  
  10. class FavoriteRepository implements RepositoryInterface
  11. {
  12. /**
  13. * @param int $id
  14. *
  15. * @return Favorite
  16. */
  17. public function getById(int $id): Favorite
  18. {
  19. return Favorite::query()->find($id);
  20. }
  21.  
  22. /**
  23. * Get user Favorites
  24. *
  25. * @param int $perPage
  26. *
  27. * @return Collection<Favorite>
  28. */
  29. public function getFavorites(int $perPage): Collection
  30. {
  31. return Favorite::query()
  32. ->where('user_id', getUser('id'))
  33. ->orderByDesc('created_at')
  34. ->with('story')
  35. ->paginate($perPage);
  36. }
  37. }