Laravel:Parse error: syntax error の理由
Laravel:Parse error: syntax error の理由
『Parse error: syntax error』が出て1時間ほど足止めしてしまいました。
自戒を込めて備忘録へ記そうと思います。
Parse error: syntax error とは
「PHPのスクリプトが間違えてるよ」というエラーです。
今までも何度か経験してますが、その殆どが【@endのつけ忘れ】でした。
- @foreach でスタートしてるのに @endforeach が無い
- @if で @else はあるけど@endif が無い
こんな奴です。
でも、今回は@foreach ~~~~~ @endforeach とばっちり閉じています。
<table id="list" style="width:100%;">
<colgroup>
<col style="width:35%">
<col style="width:35%">
<col style="width:30%">
</colgroup>
<tr>
<th class="td_text smallfont">カート</th>
<th class="td_text smallfont">コード</th>
<th class="td_text smallfont">タグ名</th>
</tr>
@foreach($saleitemcategories as $saleitemcategory)
@foreach({$saleitemcategory->categorycarttag as $categorycarttag)
<tr data-href="/saleitemcategories/{{$categorycarttag->id}}/edit" class="mouse_over_icon">
<td class="td_text">
<p class="overflow smallfont" style="width:95%;">{{ optional($categorycarttag->cart)->name}}</p>
</td>
<td class="td_text">
<p class="overflow smallfont" style="width:95%;">{{ $categorycarttag->cart_tagcode}}</p>
</td>
<td class="td_text">
<p class="overflow smallfont" style="width:95%;">{{ optional($categorycarttag->cart_tag)->name}}</p>
</td>
</tr>
@endforeach
@endforeach
</table>
原因は@foreach の中の『 { 』でした
2つ目の@foreachを見るとこんな状態だったんです。
@foreach( { $saleitemcategory->categorycarttag as $categorycarttag)
まじか...この1文字のために1時間かけたのか...。
まとめ
『Parse error: syntax error』が出たら思い込みは捨てスクリプトをしっかり確認しましょう。


