从数据库中提取数据时,我得到id
作为字符串。
$alphabets = new Alphabet();
return $alphabets->pluck('name', 'id');
Output
{
"1": "Apple",
"2": "Ball",
"3": "Cat"
}
Expected
{
1: "Apple",
2: "Ball",
3: "Cat"
}
但是,当我逆转ID
and name
,
return $alphabets->pluck('id', 'name');
我得到的 id 是整数。
{
"Apple": 1,
"Ball": 2,
"Cat": 3
}
我不确定幕后发生了什么。但是如何获取整数形式的 ID 呢?实际上,旧的闪存会话没有设置值,因为1 vs "1"
在集体形式中。
{!! Form::select('alphabet', $alphabets, null, ['class' => 'form-control', 'multiple' => true]) !!}