2017-07-06 10:05
浏览 332


I want to connect my dropdown select form with database, currentli I have sth like this:

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

And this is my controller:

        $clients = Client::all();

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

and i get much fields. I want only one with items from db. How to do it?

图片转代码服务由CSDN问答提供 功能建议

我想将我的下拉选择表单与数据库连接,currentli我有这样的: @foreach($ clients as $ client) {!! Form :: select('connected_with', ['name'=> $ client-> name。$ client-> surname ])!!} @endforeach


  $ clients = Client :: all(); 
返回视图('report_create')  - > with('clients',$ clients); 

我得到了很多字段。 我只想要一个来自db的项目。 怎么做?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanjiao8871 2017-07-06 10:08

    If you want to create select list of clients, use pluck():

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

    To make it work, you'll also need to define an accessor in the Client model:

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

    Then just create the list:

    {!! Form::select('connected_with', $clients) !!}
    打赏 评论

相关推荐 更多相似问题