从数据库中提取时,我得到id
字符串。
$alphabets = new Alphabet();
return $alphabets->pluck('name', 'id');
输出
{
"1": "Apple",
"2": "Ball",
"3": "Cat"
}
预期的
{
1: "Apple",
2: "Ball",
3: "Cat"
}
但是,当我反转ID
and时name
,
return $alphabets->pluck('id', 'name');
我得到 id 作为整数。
{
"Apple": 1,
"Ball": 2,
"Cat": 3
}
我不确定幕后发生了什么。但是我怎样才能得到整数 ID 呢?实际上,旧的 Flash 会话没有设置值,因为1 vs "1"
在 Form Collective 中。
{!! Form::select('alphabet', $alphabets, null, ['class' => 'form-control', 'multiple' => true]) !!}