我目前正在处理表单中的下拉菜单,它正在返回索引值,例如选中此框时为0,1,2。我需要它来返回框内的文字文本,例如'Server One','Server Two'。我正在使用laravel集体形式。附件是表单的代码段。任何帮助将非常感激!变量$ statuses是数据库中所有服务器的列表。
@extends('layouts.app')
@section('content')
<h1></h1>
<h1>Edit Incident</h1>
{!! Form::open(['action' => ['IncidentsController@update', $incident->id], 'method' =>'POST']) !!}
<div class="form-group">
{{Form::label('title','Title')}}
{{Form::text('title',$incident->title,['class' => 'form-control', 'placeholder' => 'Title'])}}
{{Form::label('body','Body')}}
{{Form::textarea('body',$incident->body,['id' => 'article-ckeditor','class' => 'form-control', 'placeholder' => 'Body text'])}}
{{Form::label('status','Server Status:')}}
<br>
{{Form::label('status','Resolved:')}}
{{Form::radio('status', 'Resolved' , false) }}
<br>
{{Form::label('status','Unresolved:')}}
{{Form::radio('status', 'Unresolved' , true) }}
<br>
{{ Form::label('server', 'Server:') }}
<br/>
{{Form::select('server', $statuses),['name' => "server",'class' => 'form-control']}}
</div>
{{Form::hidden('_method', 'PUT')}}
{{Form::submit('Submit', ['class' => 'btn btn-primary'])}}
{!! Form::close() !!}
dd($server)
@endsection
createIncident:
public function createIncident(){
$statuses = Status::pluck('server');
dd($statuses);
return view('createIncident', ['statuses' => $statuses]);
}
答案 0 :(得分:0)
最终改变了我显示和存储表单本身的方式,并使用了select标签来修复它。
<select name="server">
@foreach($statuses as $key => $value)
<option>{{$value}}</option>
@endforeach
</select>