我的刀片文件中有这个:
<select class="form-control" name="category" id="category">
@foreach ($category as $h)
@if ({{$h->id}} == {{$directory->category}})
<option value="{{$h->id}}" selected>{{$h->name}}</option>
@else
<option value="{{$h->id}}">{{$h->name}}</option>
@endif
@endforeach
</select>
和控制器:
$directory= Directory::find($id);
$category = StoreCategory::all();
return view('edit')->with('category', $category)->with('directory', $directory);
打开编辑后,我收到#34;语法错误,意外&#39;&lt;&#39;&#34;
尝试删除if-else条件并且工作正常。
答案 0 :(得分:8)
您不应在{{ ... }}
区块中使用if
。将其更改为:
@if ( $h->id == $directory->category )