89016

unexpected endforeach in blade template

Question:

I have a blade template in laravel in laravel that displays a tab view. The tabs are different eventtypes and in the tabs are the events per type. This view worked fine until today. The only thing that changed is that I made it possible to soft-delete events.

The error I get is the following:

syntax error, unexpected 'endforeach' (T_ENDFOREACH)

This is the entire source code of the template:

@extends('master') @section('title', '- Kalenderbeheer') @section('head') {{ HTML::script('Script/lib/dataTables.js'); }} <script> $(document).ready(function(){ $("#EventTypeTabs").tab(); $(".eventtable").dataTable({ paging: false, info: false, "aoColumns": [ null, null, null, { "asSorting": [] } ] }); $(".eventtable tr").click(function(){ if ($(this).data("id")) location.href = "/kalender/admin/" + $(this).data("id"); }) }); </script> @stop @section('body') <div class="row"> <div class="col-md-6 col-md-offset-1">

Kalenderbeheer

</div> <div class="col-md-4 rtl"> <a href="/kalender/admin/nieuw">Nieuwe activiteit toevoegen</a> </div> </div> <div class="row"> <div class="col-md-10 col-md-offset-1"> <ul class="nav nav-tabs" style="margin-bottom: 15px;" id="EventTypeTabs"> @foreach ($eventtypes as $et) <li @if($et->id == 1) class="active" @endif> <a href="#{{{ $et->getFormattedName() }}}" data-toggle="tab">{{{ $et->name }}}</a> </li> @endforeach </ul> <div class="tab-content eventtypetabs"> @foreach ($eventtypes as $et) <div class="tab-pane fade @if ($et->id == 1)active in@endif" id="{{{ $et->getFormattedName() }}}"> @if (count($et->events) > 0) <table class="table table-striped eventtable"> <thead> <tr> <th>#</th> <th>Datum</th> <th>Naam</th> <th></th> </tr> </thead> <tbody> <?php $c = 0; ?> @foreach ($et->events as $event) <tr data-id="{{ $event->id }}"> <td>{{ ++$c }}</td> <td>{{ preg_replace("/\d{2}:\d{2}:\d{2}/", "", $event->start) }}</td> <td>{{{ $event->name }}}</td> <td>X</td> </tr> @endforeach </tbody> </table> @endif </div> @endforeach </div> </div> </div> @stop

The error appears on the last @endforeach. This is a screenshot of the error: <img alt="laravel error" class="b-lazy" data-src="https://i.stack.imgur.com/tr9Hl.png" data-original="https://i.stack.imgur.com/tr9Hl.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

Answer1:

You just need to add a space before @endif (line 48)

<div class="tab-pane fade @if ($et->id == 1)active in @endif" id="{{{ $et->getFormattedName() }}}">

Also, it's better to use the ternary operator:

class="tab-pane fade {{ $et->id == 1 ? 'active in' :''}}"

Recommend

  • Left fixed columns with table colspan
  • Avoid Rendering “No Data Available in the table” in Datatables
  • Can you use DataSet and DataTables in a Portable Class Library
  • Why isn't obj.style.left = “200px”; working in this code?
  • How to pass a value from ASP.NET MVC controller to ASP.NET webforms control inside MVC View?
  • How to get latest version of a artifact on Bintray using JSONP
  • Tell Git to stop prompting me for conflicts when none really exist?
  • How to return DataSet (xsd) in WCF
  • Uncaught TypeError: $(…).select2 is not a function
  • During installation of Django, why do I keep getting ImportError: No module named django?
  • Kendo barchart category labels left and right based on value
  • Roxygen error “Skipping invalid path”
  • Button click event not firing in jQuery
  • wxPython: displaying multiple widgets in same frame
  • error importing numpy
  • Chart.js Multiple dataset
  • How do I get HTML corresponding to current DOM tree?
  • chrome.tabs.executeScript only fires when the Developer Console is open
  • JQuery Internet Explorer and ajaxstop
  • Very simple C++ DLL that can be called from .net
  • JSON response opens as a file, but I can't access it with JavaScript
  • OpenGL 3.3 on Mac OSX El Capitan with LWJGL
  • Jquery UI tool tip close icon
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Display issues when we change from one jquery mobile page to another in firefox
  • req.body is undefined - nodejs
  • Modifying destination and filename of gulp-svg-sprite
  • Change an a tag attribute in JavaScript based on screen width
  • Importing jscolor library in angular 2
  • To display the title for the current loaction in map in iphone
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • trying to dynamically update Highchart column chart but series undefined
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal