修改Laravel中最外面的资源的包装 [英] Modify the wrapping of the outer-most resource in Laravel

查看:50
本文介绍了修改Laravel中最外面的资源的包装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想修改最外面的资源的包装.在文档中,有一种有关如何删除默认数据"的解决方案换行,但我找不到如何将其更改为另一个键.

I want to modify the wrapping of the outer-most resource. In documentation there is a solution on how to remove the default "data" wrap but I can't find how to change it to another key.

推荐答案

通过 Resource :: withoutWrapping()删除默认值,然后将数据手动包装在Resource类中:

Remove the default via Resource::withoutWrapping(), and then manually wrap the data in the Resource class:

public function toArray()
    {
        return [
            "my-custom-key" => $this->resource->toArray()
        ];
    }

这篇关于修改Laravel中最外面的资源的包装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆