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

Laravel 5.2 - pluck() method returns array(Laravel 5.2 - pluck() 方法返回数组)
本文介绍了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 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() 方法呢?

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() 方法返回数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)