Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何获取下拉列表以返回文本值而不是索引值_Php_Mysql_Laravel_Visual Studio Code - Fatal编程技术网

Php 如何获取下拉列表以返回文本值而不是索引值

Php 如何获取下拉列表以返回文本值而不是索引值,php,mysql,laravel,visual-studio-code,Php,Mysql,Laravel,Visual Studio Code,我目前正在处理表单中的一个下拉列表,当选中该框时,它将返回索引值,例如0,1,2。我需要它返回框中的文本,例如“服务器1”、“服务器2”。我正在与拉威尔集体组织合作。附件是表单的代码段。任何帮助都将不胜感激!变量$status是数据库中所有服务器的列表 @extends('layouts.app') @section('content') <h1></h1> <h1>Edit Incident</h1> {!! Form

我目前正在处理表单中的一个下拉列表,当选中该框时,它将返回索引值,例如0,1,2。我需要它返回框中的文本,例如“服务器1”、“服务器2”。我正在与拉威尔集体组织合作。附件是表单的代码段。任何帮助都将不胜感激!变量$status是数据库中所有服务器的列表

@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

最终改变了我显示和存储表单本身的方式,并使用select标记来修复它

   <select name="server">
       @foreach($statuses as $key => $value)
           <option>{{$value}}</option>
       @endforeach
   </select>

@foreach($状态为$key=>$value)
{{$value}}
@endforeach

我不知道laravel,但我猜它使用数组的键作为选项的值?也许使用服务器名称作为
$statuses
数组的键可以解决这个问题?如果您想继续使用
表单:
您需要提供
$statuses=['server one'=>'server one']@Kyslik那么对于每台服务器我都必须这样做吗?询问的原因是,随着时间的推移,将添加许多服务器。您需要编写生成数组的代码。$statuses是一个数组,我将使用方法调用中的代码以及die和dump的结果更新该问题。
没有值属性?不需要它,我不知道确切的原因,但我会假设它是因为当我执行$key=>$value时,它会自动将$value存储为value属性。奇怪的是,如果我添加了一个value属性,它实际上会破坏它。
   <select name="server">
       @foreach($statuses as $key => $value)
           <option>{{$value}}</option>
       @endforeach
   </select>