0
<select class="form-control" id="package_id" name="package_id">
    @foreach($packages as $package)
        <option value="{{$package->id}}">{{$package->name}}</option>
    @endforeach
</select>

Is there a way to set the "initial" value before selecting it? Standard its the first option but is there a way to set it too the second or third one?

1 Answers1

0

the <option> HTML tag has an attribute called selected you can set on an option to have it be selected by default. You can use the PHP ternary statement to decide when to assign it.

@foreach($packages as $package)
    <option value="{{$package->id}}" {{ $package->selected ? 'selected="selected"' : '' }}>{{$package->name}}</option>
@endforeach

Replace $package->selected with whatever logic you want to use to choose which option is selected, it needs to evaluate to a boolean.

Alec Joy
  • 1,848
  • 8
  • 17