Laravel- why does my blade file give unexpected end of file when if, else & endif are all present?

846 views php
1

I'm working on a Laravel application, and have a function to export a PDF file that is generated based on input that the user has submitted to a form.

I am trying to make the content of that PDF conditional, based on the value of one of the PHP variables, so have added the @if, @else and @endif conditions to the blade file, but for some reason, now get an error in the console when trying to export the PDF:

Parse error: syntax error, unexpected end of file, expecting elseif (T_ELSEIF) or else (T_ELSE) or endif (T_ENDIF) (View: /home/.../reminder.blade.php)

The blade.php file is currently written with:

<html>

<head>
    <title>Provisional Reminder</title>
    <link rel="stylesheet" href="{{ url('') }}/css/pdf.css">
</head>
@if(( count( $request->transactionItem ) == 1 ) && $request->transactionItem->currentStatusId == '1010') 

<body >
    <p>if statement run in reminder.blade.php</p>
</body>

@else
<body>
    <p>else statement run in reminder.blade.php</p>
</body>
@endif

</html>

The else & endif are both there, so why am I getting this error? How can I get the content of the blade file to be displayed conditionally, based on the value of the request variable?

The PDF is being generated by the PHP function:

private function generateProvTaxPDF($transactions, $globalData)
{
    $data = ['transactions' => $transactions, 'globalData' => $globalData];
    //dd("transactions: ", $transactions);

    //$view = \View::make('pdfs.reminder', $data);
    //$contents = $view->render();

    //echo $contents;
    //die;

    $pdf = \PDF::loadView('pdfs.reminder', $data) 
    ->setOption('encoding', 'utf-8')
    ->setOption('margin-top', 0)
    ->setOption('margin-bottom', 0)
    ->setOption('margin-left', 0)
    ->setOption('margin-right', 0)
    ->setPaper('a4');

    return $pdf->stream();
}

answered question

1 Answer

9

Try replacing the first @if statement with this

@if( count( $request->transactionItem ) == 1  && $request->transactionItem->currentStatusId == '1010') 

posted this

Have an answer?

JD

Please login first before posting an answer.