Laravel 5.2 - pluck() method returns array(Laravel 5.2 - pluck() 方法返回数组)
问题描述
我正在尝试升级我的项目 L5.1 -> L5.2.在升级指南中,我不清楚一件事:
I'm trying to upgrade my project L5.1 -> L5.2. In upgrade guide there's one thing which isn't clear for me:
集合、查询构建器和 Eloquent 查询上的 lists 方法builder 对象已重命名为 pluck.方法签名保持不变.
The
listsmethod on the Collection, query builder and Eloquent query builder objects has been renamed topluck. The method signature remains the same.
没关系,将重构从 lists() 重命名为 pluck() 不是问题.但是 L5.0 和 L5.1 中有用的 pluck() 方法呢?
That's ok, rename refactoting from lists() to pluck() isn't a problem. But what with useful pluck() method which was in L5.0 and L5.1?
来自 5.0 文档:
从一行中检索单列
$name = DB::table('users')->where('name', 'John')->pluck('name');
L5.2 中旧的 pluck() 方法的替代方法是什么?
What is the alternative for old pluck() method in L5.2?
更新:
示例:
var_dump(DB::table('users')->where('id', 1)->pluck('id'));
L5.1:
// int(1)
L5.2:
// array(1) { [0]=> int(1) }
推荐答案
pluck() 目前的替代方案是 value().
The current alternative for pluck() is value().
这篇关于Laravel 5.2 - pluck() 方法返回数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Laravel 5.2 - pluck() 方法返回数组
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
