I am trying to hide the tags select if there are no tags in my database so that I don't see an empty select element with no options, however, the obvious solution doesn't seem to work.
@if (!empty($tags))
<label for="tags">Tag</label>
<select name='tags'>
@foreach($tags as $tag)
<option value='{{$tag->id}}'>{{$tag->name}}</option>
@endforeach
</select>
@endif
答案 0 :(得分:2)
It's a collection.
Do this:
if (!$tags->isEmpty()) {
// your code
}