vendredi 27 novembre 2015

Laravel 5.1: Show all selected tags when update article

I have a problem to show all selected tags when I try to update some article.

I'm newb in laravel and php so, here is my code:

<select name="tags[]" class="form-control" multiple="multiple">
    @foreach($tags as $key => $value)
        @foreach($news->tags as $tag)
            <option value="{{ $key }}" @if($tag->name == $value) selected @endif>{{ $value }}</option>
        @endforeach
   @endforeach
</select>

But the result is not that I'm actualy expect:

<select name="tags[]" class="form-control" multiple="multiple">
    <option value="1" selected="">1</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="3" selected="">3</option>
</select>

It must be like this:

<select name="tags[]" class="form-control" multiple="multiple">
    <option value="1" selected>1</option>
    <option value="2">2</option>
    <option value="3" selected>3</option>
</select>

How can i do that? Thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire