最初是这样处理的
$data = $query->order($order)->paginate($pagesize)->toArray();
array_walk($data['data'], function (&$val){
$val['add_pro'] = "haha";
});
return $data;
后面发现官方有相关的支持
$list = User::where($where)->order($order)->paginate()->each(function($item, $key){
$item->nickname = 'think';
})->toArray();
两者各有各的适用范围,视情况使用吧
注:each()
其实不止用于分页
User::where($where)->order($order)->select()->each(function($val){
$val->nickname = 'think';
})->toArray();