$this->response->item ($topic, new TopicTransformer ()),请问怎么理解 item 中的第一个参数呢?

return $this->response->item($topic, new TopicTransformer());

不知道理解的对不对,TopicTransformer() 返回的是return中内容,而 item($topic, new TopicTransformer()); 中的 $topic,是指指定$topic->id的内容。

《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
最佳答案
  • 官方文档有定义:

    Two types of resource exist:
    
    League\Fractal\Resource\Item - A singular resource, probably one entry in a data store
    League\Fractal\Resource\Collection - A collection of resources
    The Item and Collection constructors will take any kind of data you wish to send it as the first argument, and then a “transformer” as the second argument.
  • 可以看到写法有不同,原因我分析了一下,在此
5年前 评论
讨论数量: 3
liyu001989

怎么理解。。就是用 Transformer 格式化 Model 模型。我没看懂你的表述,你可以再描述一下你哪没懂

5年前 评论

@liyu001989 谢谢,看了后面的教程就懂了。

5年前 评论
  • 官方文档有定义:

    Two types of resource exist:
    
    League\Fractal\Resource\Item - A singular resource, probably one entry in a data store
    League\Fractal\Resource\Collection - A collection of resources
    The Item and Collection constructors will take any kind of data you wish to send it as the first argument, and then a “transformer” as the second argument.
  • 可以看到写法有不同,原因我分析了一下,在此
5年前 评论

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