douzhun4124 2015-07-28 08:53
浏览 30
已采纳

Laravel5填充选择错误

Controller:

$groups = DB::table('groups')->lists('group_name');

Then Controller->Blade:

return view('dashboard')->with('groups', $groups);

And the Blade:

@if(!empty($groups))
 {!! Form::open(array('url' => '/dashboard/send_group_msg', 'method' => 'post')) !!}
  {!! Form::select('id', $groups, null, ['class' => 'form-control']) !!}
 {!! Form:close() !!}
@endif

But this returns me this error (I tryed every possible way):

FatalErrorException in *** line 14:
syntax error, unexpected ':', expecting ',' or ';'

Line 14 is my last line from document. As you can see this is basic populating a select form in L5 but doesn't work. I tryed every possible way to do it and I was close only when I put it in array like this:

$items = array();

foreach ($groups as $group)
{
    $items[$group->id] = $group->group_name;
}

But then this returns me this error:

Trying to get property of non-object

Please suggest me a proper solution.

  • 写回答

2条回答 默认 最新

  • duandang2838 2015-07-28 09:55
    关注

    After replacing your

    {!! Form:close() !!} 
    

    with

    {!! Form::close() !!}
    

    you should replace

    $groups = DB::table('groups')->lists('group_name');
    

    with

    $groups = DB::table('groups')->lists('group_name', 'id');
    

    and throw away this

    $items = array();
    
    foreach ($groups as $group)
    {
        $items[$group->id] = $group->group_name;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答