php - Laravel 5.2 - pluck() 方法返回数组

标签 php laravel eloquent query-builder laravel-5.2

我正在尝试升级我的项目 L5.1 -> L5.2。在 upgrade guide有一件事我不清楚:

The lists method on the Collection, query builder and Eloquent query builder objects has been renamed to pluck. The method signature remains the same.

没关系,将重构从 lists() 重命名为 pluck() 不是问题。但是 L5.0 和 L5.1 中有用的 pluck() 方法呢?

来自5.0 documentation :

Retrieving A Single Column From A Row

$name = DB::table('users')->where('name', 'John')->pluck('name');

L5.2 中旧的 pluck() 方法的替代方法是什么?

更新:

例子:

var_dump(DB::table('users')->where('id', 1)->pluck('id'));

L5.1:

// int(1)

L5.2:

// array(1) { [0]=> int(1) }

最佳答案

pluck() 的当前替代方法是 value()

关于php - Laravel 5.2 - pluck() 方法返回数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34405138/

相关文章:

php - 我可以从字符串中删除随机数字和字母吗?但只保留重要的

php - 通过 php curl 的多个请求会影响我的 vps 速度

php - 如何用循环更新sql中的一行?

javascript - 使用 php 将 mysql 数据转换为 javascript 图表

php - 如何在 mariadb 中使用 -> 运算符查询 JSON 列

laravel - 根据 Auth Laravel 5.5 绑定(bind)服务

php - Laravel 迁移 : Remove onDelete ('cascade' ) from existing foreign key

php - Laravel:Eloquent 如果列名包含破折号,如何获取模型的属性?

php - 在 Laravel 中搜索两个数字(价格)

php - 是否可以用 Goutte 解析 JSON?