How to hide tags select if there are no tags in my database in Laravel?

时间:2018-02-26 17:50:34

标签: php laravel

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

1 个答案:

答案 0 :(得分:2)

It's a collection.

Do this:

if (!$tags->isEmpty()) {
   // your code
}