我试图在下拉菜单中显示货币,但我需要选择值为default = 1的数据。在搜索时,我找到了一个样本并试图将它应用到我的控制器上,这就是我的意思,
$currencies = \DB::table('currencies')->where('default', 1)->lists('acronym');
它不起作用。错误信息说
Call to undefined method Illuminate\Database\Query\Builder::lists()
另外我读了一条评论,列表()已经在laravel中过时了。
我该怎么做到这一点?
这是我在控制器中的创建功能
public function create()
{
$currencies = \DB::table('currencies')->where('default', 1)->lists('acronym');
return view ('orders.create')->with('currencies', $currencies);
}
这是来自创建刀片
{{ Form::select('currency_id', $currencies, Input::old('currency_id'),null, ['class' => 'form-control input-lg','required']) }}
非常感谢你!
尝试使用 - > pluck(),
$currencies = \DB::table('currencies')->pluck('currency_name','id');
// In blade
{{ Form::select('currency_id', $currencies, null, ['class' => 'form-control input-lg','required']) }}
了解更多关于采摘here。