gpt4 book ai didi

php - 在 Blade 模板中选择Raw来创建下拉列表

转载 作者:行者123 更新时间:2023-11-29 19:06:20 26 4
gpt4 key购买 nike

数据库表有两个字段first_name 和last_name。如果我想填充下拉框,我可以使用以下代码:

{!! Form::select('driver_id',  App\Driver::pluck('first_name','id'), null, ['class' => 'form-control'])  !!} 

但是如果我想连接两个字段,我应该在我的模型上使用 SelectRow:

{!! Form::select('driver_id',  App\Driver::select(DB::raw("CONCAT(first_name,' ', last_name) AS full_name, id"))->pluck('full_name','id'), null, ['class' => 'form-control'])  !!} 

但是这个解决方案不起作用,这就是我得到的:

<select class="form-control" name="driver_id">
<option value="">Autista...</option>
<option value="11"> </option>
<option value="12"> </option>
<option value="13"> </option>
.....
</select>

也就是说......选择不会获得“full_name”字段,但会获得“id”字段。怎么解决?

最佳答案

我想你可以试试这个:

{{ Form::select('driver_id',  App\Driver::select(DB::raw("CONCAT(first_name,' ', last_name) AS full_name, id"))->lists('full_name','id'), null, ['class' => 'form-control']) }}

希望这对您有用!

关于php - 在 Blade 模板中选择Raw来创建下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43469211/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com