Return select field value in Laravel

1

How do I return the value that is in the bank of a select field and continue showing the other options for editing:

      <div class="form-group">
        <label>Tipo de imóvel</label>
        <select name="tipo_id" class="form-control">
            <option selected="disabled">Selecionar</option>
          @foreach($types as $value)
            <option>{{$value->nome}}</option>
          @endforeach
        </select>
      </div>
    
asked by anonymous 23.11.2016 / 14:34

1 answer

1

I imagine what you are looking for is this here:

 <div class="form-group">
    <label>Tipo de imóvel</label>
    <select name="tipo_id" class="form-control">
        <option disabled="disabled">Selecionar</option>
      @foreach($types as $value)
        <option {{ $property->tipo_id == $value->id ? 'selected' : '' }}  value="{{ $value->id }}">{{$value->nome}}</option>
      @endforeach
    </select>
  </div>

I'm doing a check inside option , so if the property_id is equal to the id of the type that is in the loop, it places the selected attribute.

You can not see the structure of your data, but taking into account your comment this should work for you!

    
23.11.2016 / 17:37