$list = User::where('status',1)->paginate()->each(function($item, $key){
$item['nickname'] = '11';
});官方介绍方法,无法把处理后的数据返回$list.查看TP5,each方法代码:
/**
* 给每个元素执行个回调
*
* @param callable $callback
* @return $this
*/
public function each(callable $callback)
{
foreach ($this->items as $key => $item) {
if ($callback($item, $key) === false) {
break;
}
}
return $this;
}foreach 内对$this值 没有影响;修改代码:
public function each(callable $callback)
{
foreach ($this->items as $key => $item) {
$this->items[$key] = $callback($item, $key);
if ($callback($item, $key) === false) {
break;
}
}
return $this;
}前端:$list = User::where('status',1)->paginate()->each(function($item, $key){
$item['nickname'] = '11';
return $item;
});可以正常赋值,这个是否是官方的bug?最佳答案