从 GET 变量 laravel 5.2 设置下拉值
Set a drop-down value from GET variable laravel 5.2
我在 laravel 项目中构建了以下 select 表单元素:
{!! Form::select('chapter', [1=>'First', 2=>'Second', 3=>'Third'], [2], ['multiple']); !!}
它工作正常,直到我将 chapter
添加到 URL 作为 GET 变量。
在像 project.dev/page?chapter[]=2
一样的页面上,相同的表单没有 selected 选项。
我该如何解决?
已解决!
问题出在供应商的代码中:(
\Collective\Html\FormBuilder line 719 in the method getSelectedValue($value, $selected):
return in_array($value, $selected, true) ? 'selected' : null;
但在之前的 (5.1) 和下一个 (5.3) 版本中,这一行看起来如下所示:
return in_array($value, $selected, true) || in_array((string) $value, $selected, true) ? 'selected' : null;
在该版本中,一切都按预期进行。
此外,您还可以比较源代码:
https://github.com/LaravelCollective/html/blob/5.3/src/FormBuilder.php 和
https://github.com/LaravelCollective/html/blob/5.2/src/FormBuilder.php
我在 laravel 项目中构建了以下 select 表单元素:
{!! Form::select('chapter', [1=>'First', 2=>'Second', 3=>'Third'], [2], ['multiple']); !!}
它工作正常,直到我将 chapter
添加到 URL 作为 GET 变量。
在像 project.dev/page?chapter[]=2
一样的页面上,相同的表单没有 selected 选项。
我该如何解决?
已解决!
问题出在供应商的代码中:(
\Collective\Html\FormBuilder line 719 in the method getSelectedValue($value, $selected):
return in_array($value, $selected, true) ? 'selected' : null;
但在之前的 (5.1) 和下一个 (5.3) 版本中,这一行看起来如下所示:
return in_array($value, $selected, true) || in_array((string) $value, $selected, true) ? 'selected' : null;
在该版本中,一切都按预期进行。 此外,您还可以比较源代码: https://github.com/LaravelCollective/html/blob/5.3/src/FormBuilder.php 和 https://github.com/LaravelCollective/html/blob/5.2/src/FormBuilder.php