2017-07-06 99 views
1

我想连接与数据库我的下拉列表中选择的形式,currentli我也有东西是这样的:Laravel集体形式和foreach循环

    @foreach($clients as $client) 
        {!! Form::select('connected_with', 
        ['name' => $client->name . $client->surname 
         ]) !!} 
        @endforeach 

这是我的控制器:

 $clients = Client::all(); 

     return view('report_create')->with('clients', $clients); 

,我也得到很多领域。我只需要一个来自db的项目。怎么做?

回答

0

如果你想创建客户的选择列表,使用pluck()

$clients = Client::pluck('full_name', 'id'); 
return view('report_create')->with('clients', $clients); 

要使其工作,你还需要define an accessorClient模式:

public function getFullNameAttribute() 
{ 
    return $this->name.' '.$this->surname; 
} 

然后,只需创建清单:

{!! Form::select('connected_with', $clients) !!}