I launched the following code and it works fine. The file (
/routes/web.php
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PDFController;
Route::get('/dl/file.pdf', [PDFController::class, 'generatePDF']);
/app/Http/Controllers/Frontend/PDFController.php
<?php
namespace App\Http\Controllers\Frontend;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use PDF;
class PDFController extends Controller
{
public function generatePDF()
{
$data = [
'title' => 'Welcome to Laravel',
'date' => date('m/d/Y')
];
$pdf = PDF::loadView('front.pdf', $data);
return $pdf->download('laravel.pdf');
}
}
/front/pdf.blade.php
<!DOCTYPE html>
<html>
<head>
<title>PDF - Laravel</title>
</head>
<body>
<h1>{{ $title }}</h1>
<p>{{ $date }}</p>
<p>It is a test.</p>
</body>
</html>
I know this code $pdf->download('laravel.pdf') is downloadable.
Pale Moon secured with no JavaScript allowed
Correcting web spelling inline before print