控制器:
$groups = DB::table('groups')->lists('group_name');
然后控制器->刀片:
return view('dashboard')->with('groups', $groups);
刀片:
@if(!empty($groups))
{!! Form::open(array('url' => '/dashboard/send_group_msg', 'method' => 'post')) !!}
{!! Form::select('id', $groups, null, ['class' => 'form-control']) !!}
{!! Form:close() !!}
@endif
但这给我返回了这个错误(我尝试了所有可能的方法(:
FatalErrorException in *** line 14:
syntax error, unexpected ':', expecting ',' or ';'
第14行是我在文档中的最后一行。正如您所看到的,这是在L5中填充选择表单的基础,但不起作用。我尝试了所有可能的方法,只有当我把它放在这样的数组中时,我才接近:
$items = array();
foreach ($groups as $group)
{
$items[$group->id] = $group->group_name;
}
但这给我返回了这个错误:
Trying to get property of non-object
请给我一个合适的解决方案。
更换后
{!! Form:close() !!}
带有
{!! Form::close() !!}
你应该更换
$groups = DB::table('groups')->lists('group_name');
带有
$groups = DB::table('groups')->lists('group_name', 'id');
扔掉这个
$items = array();
foreach ($groups as $group)
{
$items[$group->id] = $group->group_name;
}
您的
{!! Form:close() !!}
缺少":">
{!! Form::close() !!}