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

Размер файла: 587B
  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. $stories = (new StoryRepository())->getActiveStories()->pluck('id');
  21. $tags = Tag::query()->whereIn('story_id', $stories)->get()->pluck('tag');
  22. $tags = array_count_values($tags);
  23.  
  24. arsort($tags);
  25. return array_slice($tags, 0, $count, true);
  26. }
  27. }