2015-07-28 100 views
0

控制器:Laravel5填充選擇錯誤

$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中的選擇表單,但不起作用。我tryed一切可能的方式來做到這一點,我很接近,只有當我把它放在數組是這樣的:

$items = array(); 

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

但隨後這將返回我這個錯誤:

Trying to get property of non-object 

請建議我一個妥善的解決辦法。

回答

1

{!! 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; 
} 
+0

哦,非常感謝。我犯了多麼愚蠢的錯誤。 – Khanasyubighi

+0

@ user1560295我很受歡迎 – M0rtiis

1

{!! Form:close() !!} 

缺少一個 ':'

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