Laravel 5.2 - pluck()方法返回数组 [英] Laravel 5.2 - pluck() method returns array

查看:3555
本文介绍了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查询
构建器对象已被重命名到 pluck 。方法签名
保持不变。

The lists method on the Collection, query builder and Eloquent query builder objects has been renamed to pluck. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆