Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Tchopa's avatar

404 not found when trying to generate PDF using DomPDF package

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

0 likes
5 replies
SilenceBringer's avatar
Level 55

@tchopa because in your routes you have statements (plural), but in url - statement (suingular)

'statements/{statement}/download'

'/statement' . '/' . $statement->id . '/download'
1 like
Sinnbeck's avatar

You are missing an s in statements

<a class="btn btn-primary btn-sm" href="{{ url('/statements' . '/' . $statement->id . '/download') }}" >Download</a> 
1 like
Tchopa's avatar

Thanks guys, that worked. What a silly mistake by me. You legends!!

Please or to participate in this conversation.