php - Laravel:如何从嵌套数组中检索数据
问题描述
我正在尝试从数据库中的表中检索特定列。列名是verification_type_id
,表名是certificate_verification_type
。
当我vardump()
使用用于检索列的变量时,我得到的是:
array(2)
{
[14]=> array(2)
{
["certificate_id"]=> int(9)
["verification_type_id"]=> int(2)
}
[15]=> array(2)
{
["certificate_id"]=> int(9)
["verification_type_id"]=> int(3)
}
}
这是我的 laravel 雄辩的查询:
$certVeriType = CertificateVerificationType::all()->where('certificate_id', $certType)->toArray();
我怎样才能只从表中检索“verification_type_id”列。这是表的迁移文件:
$table->integer('certificate_id');
$table->integer('verification_type_id');
$table->index('certificate_id');
提前致谢!
解决方案
添加 -> pluck() (pluck 方法检索给定键的所有值)到您的雄辩查询:
$certVeriType = CertificateVerificationType::all()
->where('certificate_id', $certType)
->pluck('verification_type_id')
->toArray();
推荐阅读
- push-notification - 当应用程序被杀死时,推送通知不显示消息正文。它只显示应用程序的默认图标
- android - 带有 configChanges 的 Android DayNight 主题
- go - 用结构方法反射结构
- python - Python - Selenium 不会返回上一页
- mysql - 从 MySQL 数据库中选择多个字段重复项
- jquery - 从不同页面导航到主选项卡内的子选项卡
- android - 如何使用 Android Renderscript 填充位图?
- javascript - if { ... } 外部的 Javascript XMLHttpRequest 状态
- angular - 弹性网格不适用于 p-col-#primeng Angular 5
- git - 初始推送后 Git 忽略文件(只读)