can anyone help me set the option variables on a select style drop-down in Laravel 5.1?
In my controller I have
$buildings = Warf::select('facilityname')
->distinct()
->get();
.
.
.
return view('reports.space', compact('buildings');
the 'space' view looks like
{!! Form::open() !!}
<div class="well col-sm-6 col-sm-offset-3">
<legend>Spacial Reports</legend>
<div class="form-group">
{!! Form::label('building_', 'Building:') !!}
{!! Form::select('building', $buildings, null, ['class' => 'form-control'])!!}
</div>
.
.
.
<div class="form-group">
{!! Form::submit('Submit', ['class' => 'btn btn-primary form-control']) !!}
</div>
</div>
{!! Form::close() !!}
However this results in the following HTML
<div class="form-group">
<label for="building_">Building:</label>
<select class="form-control" name="building"><option value="0">{"facilityname":"WARF"}</option></select>
</div>
Questions: A) How can I get just "WARF" to show up in the dropdown? B) Is there a way to default the selection to show no values?
Thanks, Otterman
I am using the Collective Html generator if that makes a difference
Try selecting the column as "name"
$buildings = Warf::select('facilityname as name')
->distinct()
->get();
or you might need to return that using lists, something like:
$buildings = Warf::select('facilityname as name')
->distinct()
->lists('name','id')->all() //
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.