@php $words = \App\Models\PopularKeyword::query()->orderByRaw('pk_counts DESC, pk_id ASC')->limit(5)->get(); $articles = \App\Models\Article::withoutTrashed() ->orderByRaw('article_is_top DESC, DATE(article_begin_at) DESC, article_scan_count DESC') ->get(['article_tag']); $tags = []; foreach ($articles as $article) { if (empty($article->article_tag)) continue; $tags = array_unique(array_merge($tags, array_filter(json_decode($article->article_tag)))); if (count($tags) >= 5) { $tags = array_slice($tags, 0, 5); break; } } @endphp