title: Laravel- why does my blade file give unexpected end of file when if, else & endif are all present?
body: <p>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.</p>
  
  <p>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 <code>@if</code>, <code>@else</code> and <code>@endif</code> conditions to the blade file, but for some reason, now get an error in the console when trying to export the PDF:</p>
  
  <blockquote>
    <p>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)</p>
  </blockquote>
  
  <p>The blade.php file is currently written with:</p>
  
  <pre><code>&lt;html&gt;
  
  &lt;head&gt;
      &lt;title&gt;Provisional Reminder&lt;/title&gt;
      &lt;link rel="stylesheet" href="{{ url('') }}/css/pdf.css"&gt;
  &lt;/head&gt;
  @if(( count( $request-&gt;transactionItem ) == 1 ) &amp;&amp; $request-&gt;transactionItem-&gt;currentStatusId == '1010') 
  
  &lt;body style="-webkit-font-smoothing: antialiased; font-family: 'Roboto'; font-weight: normal; margin: 0; padding: 0;"&gt;
      &lt;p&gt;if statement run in reminder.blade.php&lt;/p&gt;
  &lt;/body&gt;
  
  @else
  &lt;body&gt;
      &lt;p&gt;else statement run in reminder.blade.php&lt;/p&gt;
  &lt;/body&gt;
  @endif
  
  &lt;/html&gt;
  </code></pre>
  
  <p>The <code>else</code> &amp; <code>endif</code> 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?</p>
  
  <p>The PDF is being generated by the PHP function:</p>
  
  <pre><code>private function generateProvPDF($transactions, $globalData)
  {
      $data = ['transactions' =&gt; $transactions, 'globalData' =&gt; $globalData];
      //dd("transactions: ", $transactions);
  
      //$view = \View::make('pdfs.reminder', $data);
      //$contents = $view-&gt;render();
  
      //echo $contents;
      //die;
  
      $pdf = \PDF::loadView('pdfs.reminder', $data) 
      -&gt;setOption('encoding', 'utf-8')
      -&gt;setOption('margin-top', 0)
      -&gt;setOption('margin-bottom', 0)
      -&gt;setOption('margin-left', 0)
      -&gt;setOption('margin-right', 0)
      -&gt;setPaper('a4');
  
      return $pdf-&gt;stream();
  }
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <p>The code in my PHP controller that calls this function is:</p>
  
  <pre><code>public function getSingleTransactionPDF(Request $request)
  {
      $transactionItem = $request-&gt;input('transactionItem');
  
      $vTransactionItem = (array)DB::table('transaction.vTransactionPDF')-&gt;where('transactionItemId', $transactionItem['transactionItemId'])-&gt;first();
  
      if (!empty($vTransactionItem))
      {
          $transactionItem = array_merge($transactionItem, $vTransactionItem);
  
          $loggedInUser = auth()-&gt;user();
          $globalData = $this-&gt;retrieveGlobalPDFData();
          $transactionsData = $this-&gt;retrievePDFPrimaryLineItemData([$transactionItem], $loggedInUser);
  
          dd("transactionsData, globalData: ", $transactionsData, $globalData);
  
          return $this-&gt;generateProvTaxPDF($transactionsData, $globalData);
      }
      else
      {
          return response()-&gt;json([
              'error' =&gt; true,
              'message' =&gt; 'Transaction not found.',
          ], 404);
      }
  }
  </code></pre>
  
  <p>If I comment out the <code>dd("transactionsData ...", ...)</code> line here, I get the <code>Parse error</code> I've mentioned above. However, if I leave this <code>dd()</code> in, I can see the variables hold the values I'm expecting, and a PDF is downloaded, although it doesn't actually load when I try to open it- it comes up with an error.</p>