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

Размер файла: 479B
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. namespace App\Repositories;
  6.  
  7. use App\Models\Tag;
  8.  
  9. class TagRepository implements RepositoryInterface
  10. {
  11. /**
  12. * Get popular tags
  13. *
  14. * @param int $count
  15. *
  16. * @return array
  17. */
  18. public function getPopularTags(int $count = 15): array
  19. {
  20. $tags = Tag::query()->get()->pluck('tag');
  21. $tags = array_count_values($tags);
  22.  
  23. arsort($tags);
  24. return array_slice($tags, 0, $count, true);
  25. }
  26. }