Php 有没有什么优雅的方法可以降低拉维5的口才水平?

Php 有没有什么优雅的方法可以降低拉维5的口才水平?,php,laravel,eloquent,Php,Laravel,Eloquent,TestController.php $result = GoodsSku::with(['media' => function ($query) { $query->select('media_resource.id', 'media_resource.full_path'); }])->whereIn('id', [28])->get(); dd($result); 下面是$result的内容 array:1 [▼ 0 =

TestController.php

    $result = GoodsSku::with(['media' => function ($query) {
        $query->select('media_resource.id', 'media_resource.full_path');
    }])->whereIn('id', [28])->get();
    dd($result);
下面是$result的内容

array:1 [▼
  0 => array:22 [▼
    "id" => 28
    "goods_id" => 14
    "title" => phone
    "has_cover" => array:7 [▼
      "id" => 289
      "media_id" => 289
      "entity_id" => 28
      "media" => array:20 [▼
        "id" => 289
        "path" => "2015/11/08/fd1bf228_pic_show01.jpg"
        "full_path" => "http://example.com/2015/11/08/fd1bf228_pic_show01.jpg"
        "extension" => "jpg"
        "deleted_at" => null
      ]
    ]
    "goods" => array:7 [▼
      "id" => 289
      "title" => phone goods
      "goods_sku_id" => 28
      "category_id" => 3
      "category" => array:20 [▼
        "id" => 3
        "name" => "mobile"
      ]
    ]
  ]
]    
通常,我通过
$result->has\u cover->media->fullpath获得完整路径

我想通过
$result->goods->category->name
获取类别名称

您知道,这对前端开发人员(FE)不友好

关系越多,给FE带来的麻烦就越多

有没有什么优雅的方法可以使这个$result对FE来说是友好的,并且使用雄辩的(With method)

可能是这样的
$result->full\u path
$result->media.full\u path


非常感谢。

请向我展示您的模型我认为您应该使用
hasManyThrough
关系。可能
$result->fetch('has_cover.media.full_path')
。请向我展示您的模型我认为您应该使用
hasManyThrough
关系。可能
$result->fetch('has_cover.media.full_path')