【发布时间】:2017-12-01 16:39:11
【问题描述】:
从数据库中提取时,我得到 id 作为字符串。
$alphabets = new Alphabet();
return $alphabets->pluck('name', 'id');
输出
{
"1": "Apple",
"2": "Ball",
"3": "Cat"
}
预期
{
1: "Apple",
2: "Ball",
3: "Cat"
}
但是,当我反转ID 和name 时,
return $alphabets->pluck('id', 'name');
我将 id 设为整数。
{
"Apple": 1,
"Ball": 2,
"Cat": 3
}
我不确定幕后发生了什么。但是我怎样才能得到整数 ID 呢?实际上,旧的 flash 会话没有设置值,因为 Form Collective 中的1 vs "1"。
{!! Form::select('alphabet', $alphabets, null, ['class' => 'form-control', 'multiple' => true]) !!}
【问题讨论】:
标签: php json forms laravel pluck