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"
}
]
}
}
关于 LearnKu
多了一层吧 "mcar_consults"