問題描述
我正在嘗試升級我的項目 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:
集合、查詢構(gòu)建器和 Eloquent 查詢上的 lists
方法builder 對象已重命名為 pluck
.方法簽名保持不變.
The
lists
method on the Collection, query builder and Eloquent query builder objects has been renamed topluck
. The method signature remains the same.
沒關(guān)系,將重構(gòu)從 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()
.
這篇關(guān)于Laravel 5.2 - pluck() 方法返回數(shù)組的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!