Transformer 对 item,array 为什么没反应呢?

    public function index(Request $request, Consult $consult)
    {
        return $this->response->collection($this->user()->consults, new ConsultTransformer());
    }

Transformer:

class ConsultTransformer extends TransformerAbstract
{
    public function transform(Consult $consult)
    {
        return [
            'id' => $consult->id,
            'username' => $consult->username,
        ];
    }
}

响应:
item:

{
    "status": "success",
    "code": "200",
    "data": {
        "mcar_consults": [
            {
                "id": 3,
                "username": "watts2",
                "mobile": "17682310000",
                "sales_id": null,
                "due_at": null,
                "shop_address": null,
                "delivery_type": "到店提车",
                "follow_status": "新咨询",
                "content": null,
                "product_id": 50,
                "order_id": null,
                "customer_id": 8,
                "count": 24,
                "status": 1,
                "created_at": "2018-11-26 12:22:50",
                "updated_at": "2018-11-26 12:22:50"
            },
            {
                "id": 4,
                "username": "watts3",
                "mobile": "17682310000",
                "sales_id": null,
                "due_at": null,
                "shop_address": null,
                "delivery_type": "到店提车",
                "follow_status": "新咨询",
                "content": null,
                "product_id": 50,
                "order_id": null,
                "customer_id": 8,
                "count": 24,
                "status": 1,
                "created_at": "2018-11-26 12:22:54",
                "updated_at": "2018-11-26 12:22:54"
            }
        ]
    }
}

array:

{
    "status": "success",
    "code": "200",
    "data": {
        "mcar_consults": [
            {
                "id": 3,
                "username": "watts2",
                "mobile": "17682310000",
                "sales_id": null,
                "due_at": null,
                "shop_address": null,
                "delivery_type": "到店提车",
                "follow_status": "新咨询",
                "content": null,
                "product_id": 50,
                "order_id": null,
                "customer_id": 8,
                "count": 24,
                "status": 1,
                "created_at": "2018-11-26 12:22:50",
                "updated_at": "2018-11-26 12:22:50"
            },
            {
                "id": 4,
                "username": "watts3",
                "mobile": "17682310000",
                "sales_id": null,
                "due_at": null,
                "shop_address": null,
                "delivery_type": "到店提车",
                "follow_status": "新咨询",
                "content": null,
                "product_id": 50,
                "order_id": null,
                "customer_id": 8,
                "count": 24,
                "status": 1,
                "created_at": "2018-11-26 12:22:54",
                "updated_at": "2018-11-26 12:22:54"
            }
        ]
    }
}

colleciton:

{
    "status": "success",
    "code": "200",
    "data": {
        "data": [
            {
                "id": 3,
                "username": "watts2"
            },
            {
                "id": 4,
                "username": "watts3"
            }
        ]
    }
}
相信时间和变化
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
讨论数量: 1

多了一层吧 "mcar_consults"

5年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!