$items = Item::with('product')->paginate(10);

    $items = $items->map(function($product){
          $product->name = "Test";
          return $product; 
    });

    return response()->json(['items' => $items]);

In my view blade on console paginate objects not showed?

推荐答案

As, given in Laravel docs, map() method creates a new collection. To modify the values in the current collection, use transform() method.

$items->getCollection()->transform(function ($product) {
    $product->name = "Test";
    return $product;
});

此外,因为,paginator的物品是一个集合.你可以直接在$items上使用foreach

foreach ($items as $item)
{
 $item->name = "Test";
}

Laravel相关问答推荐

Laravel使用PostgreSQL显示";`try 读取null`上的属性,而不是SQL错误消息

调用字符串上的成员函数

当使用Laravel eloquent查询100000条数据时速度很慢

安卓 retrofit |发布自定义对象(将 json 发送到服务器)

验证规则 required_if 与其他条件(Laravel 5.4)

克隆后设置 Laravel 项目

Laravel 5.3 创建模型返回字段没有默认值

Laravel 5在blade中 echo 包含html的会话变量

你如何找到 Laravel 外观背后的底层类?

laravel 5 中的登录事件处理

未找到列:1054 未知列 laravel

将 Laravel 集合附加到另一个集合

Laravel - DecryptException:'MAC 无效'

Laravel 如何从子域 URL 中删除api前缀

Laravel 删除集合中的第一项

Laravel Route 模型与关系绑定

如何在 Laravel 中显示动态复选框的旧数据?

Laravel - artisan不工作

如何在 laravel eloquent 中保存布尔值

没有Access-Control-Allow-Origin标头 - Laravel