Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LaraBABA's avatar

Create dropdown menu in Laravel 5.5 with bootstrap 3

Hello,

I am struggling with this one, I would like to have 2 types of dropdown menu templates for my IDE so I can just copy/paste them when needed.

I cannot work out how to use blade and the dropdowns when the data is pulled from the database Select a Town @if ($towns)

                     @foreach($towns as $town)

                       {{ how to render the options here? }}

                     @endforeach

                     @endif
                      </select>
                     @if ($errors->has('towns'))
                   @endif <span class="help-block">
                             <strong>{{ $errors->first('towns') }}</strong>
                         </span>
                     @endif
                 </div>
             </div>

Also how to keep the value of the drop down if there is an error (on page refresh) please.

Thank you.

0 likes
3 replies
LaraBABA's avatar

Ok I think I got it....

{!! $town->id !!} in value and {!! $town->name !!} in the option itself.

tisuchi's avatar

Yes. You are right.

Here is the full example-

@foreach($towns as $town)
    
    <option value="{{ $town->id }}"> {{ $town->name }} </option>

 @endforeach
3 likes

Please or to participate in this conversation.