O
O
OstapO2019-01-16 17:29:23
Laravel
OstapO, 2019-01-16 17:29:23

How to make active the current value of an option for a select?

It is necessary to make an active option on onload in accordance with the title
5c3f3ebad965c016297011.jpeg
I pull the data from the database and in the blade I make the output as follows:

@foreach ($suggestions as $value)
   <option value="{{ $value->id }}">{{ $value->title }}</option>
@endforeach

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kupurim, 2019-01-16
@OstapO

<option 
  value="{{ $value->id }}" 
  @if($value->id === $youId)
    selected
  @endif
>
  {{ $value->title }}
</option>

V
Vlad, 2019-01-16
@Result007

There is a more compact solution using Laravel Forms & HTML

{{ Form::select('your_select_name', $suggestions, $youId, ['class' => 'your-select-class']) }}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question