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"
            }
        ]
    }
}
相信时间和变化
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 1

多了一层吧 "mcar_consults"

6年前 评论

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