orderByDesc('published_at')->get(['id', 'title', 'slug', 'published_at']); $archives = $posts->groupBy(fn (Post $post) => $post->published_at->format('Y')) ->map(fn ($yearPosts) => $yearPosts->groupBy(fn (Post $post) => $post->published_at->format('m'))); return theme_view('archives', compact('archives')); } /** * sablog 格式:/archives-{YYYYMM}.shtml */ public function month(string $date) { if (! preg_match('/^(\d{4})(\d{2})$/', $date, $m)) { abort(404); } [$year, $month] = [$m[1], $m[2]]; $start = Carbon::create((int) $year, (int) $month, 1)->startOfMonth(); $end = (clone $start)->endOfMonth(); $posts = Post::query() ->whereBetween('published_at', [$start, $end]) ->published() ->orderByDesc('published_at') ->paginate((int) blog_setting('per_page', config('blog.per_page'))); return theme_view('list', compact('posts')) ->with('archiveTitle', "{$year} 年 {$month} 月"); } }