@tchopa because in your routes you have statements (plural), but in url - statement (suingular)
'statements/{statement}/download'
'/statement' . '/' . $statement->id . '/download'
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi all,
I am using the domPDF package to generate statements that I want to be streamed when a user clicks the applicable 'Download' button next to each statement line item on the index view.
I have setup the route accordingly
Route::get('statements/{statement}/download', [StatementController::class, 'NAV'])->name('statements.download');
The applicable controller functions
public function NAV(Statement $statement)
{
$statements = Statement::all();
$navParameterOne = $statement->entity_id;
$navParameterTwo = Transaction::latest()->limit(1)->value('unit_price');
$navParameterThree = 'Test Company Pty Ltd';
$data = [
'title' => 'NAV Statement',
'date' => date('d/m/Y'),
];
$NAV_to_PDF = $this->NAVToPDFGenerate($data, $navParameterOne, $navParameterTwo, $navParameterThree);
return view('reports.statement', compact('data','navParameterOne','navParameterTwo','navParameterThree','statements'));
}
public function NAVToPDFGenerate($data, $navParameterOne, $navParameterTwo, $navParameterThree)
{
$pdf = \PDF::loadView('pdftemplates.NAV', compact('data', 'navParameterOne', 'navParameterTwo', 'navParameterThree'));
return $pdf->stream();
}
The index view with the download buttons for each statement
@foreach($statements as $statement)
<tr>
<td>{{ $loop->iteration }}</td>
<td>{{ $statement->entityNameLink->entity_name }}</td>
<td>{{ $statement->statement_type }}</td>
<td>{{ $statement->effectiveDateLink->effective_date }}</td>
<td>{{ $statement->created_at }}</td>
<td>
<a class="btn btn-primary btn-sm" href="{{ url('/statement' . '/' . $statement->id . '/download') }}" >Download</a>
The goal of this exercise is that the information for each statement will be saved and then when a client would like to download a statement, they will click the download button which will trigger the NAV function to create the pdf, then stream it to their browser. When I click the download button now, all I get is a 404 not found error with the URL displaying www.mywebsite.com/statement/1/download
Any help on this matter would be greatly appreciated. Thanks a lot
@tchopa because in your routes you have statements (plural), but in url - statement (suingular)
'statements/{statement}/download'
'/statement' . '/' . $statement->id . '/download'
Please or to participate in this conversation.