我正在努力在 Laravel Blade 的下拉列表中显示表格中的货币列表。 在下拉选项中,我想设置 csv 文件中设置的第一个值货币。 但下拉记录来自表。
如何设置上传的 csv 文件中设置的下拉列表中的第一个值。
感谢您的帮助。
以下是我的代码。
我的.blade.php
将 csv 中的货币存储在
variable = $array['currency']
<td class="currency"style="width: 10%;">
{{ Form::select('currency',$currencies , "",['class'=>"form-control select-currency",'data-plugin'=>"select2",
]) }}
</td>
我的模型.php
$currencies = Currency::all()->pluck('code', 'id');
$questions_table = \View::make('confirmation.form_questionnaire',
['questions' => $record['questions'], 'response_type' =>$record['response_type'], 'currencies' => $currencies]);
已更新
按 CSV 归档货币代码订购
$csvFiled = 'USD';
$currencies = Currency::orderByRaw("FIELD(code , '$csvFiled') DESC")->pluck('code', 'id');
或
首先获取数组中的列表
$currencies = Currency::pluck('code', 'id')->toArray();
然后找到CSV记录并设置为第一个索引
$csvValuekey = array_search('USD', $currencies); // $key = 2;
unset($users[$csvValuekey]); // Remove from main array
$fOption = [$csvValuekey => 'USD'];
$finallList = array_merge($fOption,$currencies); // Merge and set on top
现在在表单选择中添加
$finallList