jeudi 29 juin 2017

Laravel 5.4 old() selected in an edit page

In an edit page, I'm using old() so when saving the changes and missing a required field does not erase what the user had selected.

The problem is that doing so inside the foreach keeps me two selected: one the old() and another one that comes from the database. How can I make it just keep the new one if it has changed or the one in the database if it has not changed it?

<select name="level" class="form-control">
     @foreach($data['level'] as $key => $level)
         <option value="" @if(old('level') == $key) selected @else {!! ($key == $data['item']->level) ? 'selected' : '' !!} @endif></option>}
     @endforeach
</select>



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2t5kThl
via IFTTT

Aucun commentaire:

Enregistrer un commentaire