👁 查看:NewspaperController.php
路径:/home/boguraj1/.trash/app.1/Http/Controllers/NewspaperController.php
大小:1.24 KB · 修改:2026-07-17 21:45:22 · 权限:0644 · 可写
<?php

namespace App\Http\Controllers;

use App\Models\Newspaper;
use Illuminate\Http\Request;

class NewspaperController extends Controller
{
    public function show($date)
    {
        $newspaper = Newspaper::published()
            ->where('publish_date', $date)
            ->with(['pages' => fn($q) => $q->with('hotspots')->orderBy('sort_order')->orderBy('page_number')])
            ->firstOrFail();

        $allDates = Newspaper::published()
            ->orderByDesc('publish_date')
            ->pluck('publish_date')
            ->map(fn($d) => $d->format('Y-m-d'))
            ->toArray();

        // Group dates by year → month for archive sidebar
        $archiveTree = [];
        foreach ($allDates as $d) {
            [$y, $m] = explode('-', $d);
            $archiveTree[$y][$m][] = $d;
        }

        $previousEdition = Newspaper::published()
            ->where('publish_date', '<', $date)
            ->orderByDesc('publish_date')
            ->first();

        $nextEdition = Newspaper::published()
            ->where('publish_date', '>', $date)
            ->orderBy('publish_date')
            ->first();

        return view('frontend.reader', compact('newspaper', 'allDates', 'archiveTree', 'previousEdition', 'nextEdition'));
    }
}