I have this in my blade file:
<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>
and controller:
$directory= Directory::find($id);
$category = StoreCategory::all();
return view('edit')->with('category', $category)->with('directory', $directory);
Upon opening edit, I am getting "syntax error, unexpected '<'"
Tried removing the if-else condition and it is working fine.
ِYou shouldn't use {{ ... }}
in your if
block. Change it to:
@if ( $h->id == $directory->category )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.