I want to have a default value in my dropdown but I dont find how to do it.
The variable is status
and the value is 1 that is Available.
<div class="col-12">
<strong>Estatus: </strong>
<select id="status" name="status" class="form-control" autocomplete="off">
<option>-- Seleccionar --</option>
@foreach ($getStatus as $statusA)
<option {{($statusA->id == $status) ? 'selected':''}} value="{{$statusA->id}}">{{$statusA->name}}</option>
@endforeach
</select>
</div>
Its a filter that I used I want that the client always see Available
Add this
<option selected disabled>-- Seleccionar --</option>
Or if you want to have first result from your collection/array to be the default just do
@foreach ($getStatus as $statusA)
<option {{ $loop->index == 1 ? selected : '' }} value="{{$statusA->id}}">{{$statusA->name}}</option>
@endforeach
But just for UX sake I would use forelse
instead of foreach
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.