php - Laravel Blade 中的下拉默认选项错误
问题描述
在我的 laravel 刀片中,我正在尝试显示默认下拉选项,即法语中的 Select role
{!! Form::select('roles', $roles, array_merge(['' => 'Veuillez sélectionner un rôle'], $roles), ['class' => 'form-control txt_txt']) !!}
但这一直给我一个错误,
array_merge(): Expected parameter 2 to be an array, object given
我正在使用用户角色从数据库中填充该下拉列表,以下是我从控制器中的雄辩
$roles = Role::where('name','<>','Admin')->orderBy('name')->pluck('name', 'name');
如何正确显示默认选项?
解决方案
您使用Form::select
不正确。它应该是这样的:
Form::select(name, list, selected, selectAttributes, optionsAttributes, optgroupsAttributes);
所以你的代码应该是这样的:
{!!
Form::select(
'roles',
array_merge(['' => 'Veuillez sélectionner un rôle'], $roles->toArray())
'',
array(
'class' => 'form-control txt_txt'
))
!!}
推荐阅读
- transactions - 仅 SELECT 上的 Redshift 可序列化违规错误
- powershell - 关于使用 Powershell 在文本文件中增加字符串值的问题
- sql-server - 当区分大小写不匹配时,需要帮助将 Oracle 数据库连接到 SQL Server 数据库
- ionic4 - 在 Ionic4 中处理 CORS 问题
- excel - 使用 VBA 重命名 Excel 表列
- python - 如何将整数列表插入到数据库查询的字符串中 - Python 3
- java - 元素
不允许嵌套 元素 - java - 如何动态设置 setContentType("text/html") 或 setContentType("text/plain")
- python - 在python中减去日期时间,理解格式
- r - 如何使用 compareGroups 包显示中位数?