| 12345678910111213141516171819202122232425262728293031 |
- <?php
- namespace App\Http\Controllers;
- use App\Support\TeacherWeeklyStatsReportPaths;
- use Illuminate\Http\Response;
- use Symfony\Component\HttpFoundation\BinaryFileResponse;
- class TeacherWeeklyStatsReportController extends Controller
- {
- /**
- * 浏览器内联打开最近一次生成的周报 PDF(文件名带日期与 His 时间戳)。
- */
- public function open(): BinaryFileResponse|Response
- {
- $path = TeacherWeeklyStatsReportPaths::resolveLatestPdfPath();
- if ($path === null) {
- return response(
- '尚未生成周报 PDF。请在后台「老师周报统计」页面点击「生成/刷新周报」,或执行:php artisan report:teacher-weekly-pdf',
- 404
- );
- }
- $downloadName = basename($path);
- return response()->file($path, [
- 'Content-Type' => 'application/pdf',
- 'Content-Disposition' => 'inline; filename="'.$downloadName.'"',
- ]);
- }
- }
|