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

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

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

《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案
  • 官方文档有定义:

    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年前 评论

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