TeacherWeeklyStatsReportController.php 908 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Response;
  4. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  5. class TeacherWeeklyStatsReportController extends Controller
  6. {
  7. /**
  8. * 浏览器内联打开周报 PDF(固定文件名 teacher-weekly-stats-latest.pdf)
  9. */
  10. public function open(): BinaryFileResponse|Response
  11. {
  12. $path = storage_path('app/reports/teacher-weekly-stats-latest.pdf');
  13. if (! is_file($path)) {
  14. return response(
  15. '尚未生成周报 PDF。请在后台「老师周报统计」页面点击「生成/刷新周报」,或执行:php artisan report:teacher-weekly-pdf',
  16. 404
  17. );
  18. }
  19. return response()->file($path, [
  20. 'Content-Type' => 'application/pdf',
  21. 'Content-Disposition' => 'inline; filename="teacher-weekly-stats.pdf"',
  22. ]);
  23. }
  24. }