Select just grab last value

0

I have this select .

<select name="" id="" class="form-control" >
    @foreach($sede as $user)
        @if($user->idSede != $coordinadorAdm->Sede)
          <option value="{{$user->idSede}}">{{$user->nombre}}</option>
        @endif
    @endforeach
</select>

The problem is that if I need to send the $user->idSede selected, it does not take it, but it always has the last value.

    
asked by Adrian Rama 01.12.2017 в 07:43
source

1 answer

0

I could use old() (I do not know which name has its select, it is the value that should go in the old) in the following way, doing an extra validation with a if else but with the format of A ternary operator to know at what option the attribute selected is given %

<select name="" id="" class="form-control" >
  @foreach($sede as $user)
    <option value="{{ $user->idSede }}" 
     {{ ($user->idSede == $coordinadorAdm->Sede || old('sede') == $coordinadorAdm->Sede )? 'selected' : '' }}>
{{ $user->nombre }}</option>
  @endforeach
</select>
    
answered by 01.12.2017 в 08:03