jeudi 25 avril 2019

Select option with selected values returning duplicates

I'm trying to get a old selected value and show it inside a select option, as well as a non selected value, however, when i try to compare then it doesnt seen to work, so far i can only get duplicates. What's the best way to implement it?

That's how my code look like.

Role View:

@foreach($role->permission as $permissioninrole)
    <option name="permissions[]"  value=""></option>
@endforeach

@isset($permissioninrole)
    @foreach($permissions as $permission)
        @if($permissioninrole->name != $permission->name)
            <option class="rem" name="permissions[]" value=""></option>
        @endif
    @endforeach
@endisset

@empty($permissioninrole)
    @foreach($permissions as $permission)
        <option name="permissions[]" value=""></option>
    @endforeach
@endempty

How it looks. HTML

<option name="permissions[]" selected value="15">role-create</option>
<option name="permissions[]" selected value="16">role-read</option>
<option name="permissions[]" value="15">role-create</option>
<option name="permissions[]" value="16">role-read</option>
...

How it should be if role 'x' has permission role-create.

<option name="permissions[]" selected value="15">role-create</option>
<option name="permissions[]" value="16">role-read</option>
...



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire