orderByDesc('published_at')->get(['id', 'title', 'slug', 'published_at']); // 年 → 月(1-12) → 日 → 文章,用于按年/月/日索引 $archives = []; foreach ($posts as $post) { $year = $post->published_at->format('Y'); $month = (int) $post->published_at->format('m'); $day = (int) $post->published_at->format('d'); $archives[$year][$month][$day][] = $post; } 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 = blog_paginate( Post::query() ->whereBetween('published_at', [$start, $end]) ->published() ->orderByDesc('published_at') ); return theme_view('list', compact('posts')) ->with('archiveTitle', "{$year} 年 {$month} 月"); } }