Laravel 5.2 - pluck()方法返回数组 [英] Laravel 5.2 - pluck() method returns array
问题描述
我正在尝试升级我的项目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查询
构建器对象已被重命名到pluck
。方法签名
保持不变。
The
lists
method on the Collection, query builder and Eloquent query builder objects has been renamed topluck
. The method signature remains the same.
没关系,重命名从 / code>到
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?
从< a href =http://laravel.com/docs/5.0/queries> 5.0文档:
检索A单列从一列
Retrieving A Single Column From A Row
$name = DB::table('users')->where('name', 'John')->pluck('name');
旧的 pluck的替代方法()
方法在L5.2?
更新:
示例:
var_dump(DB::table('users')->where('id', 1)->pluck('id'));
L5.1:
// int(1)
L5.2:
// array(1) { [0]=> int(1) }
推荐答案
c $ c> pluck()是 value()
。
The current alternative for pluck()
is value()
.
这篇关于Laravel 5.2 - pluck()方法返回数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!