有人可以解释 ResourceCollection 和 JsonResource 之间的区别吗?
在 Laravel 6 文档中,您可以生成 2 种不同类型的资源... ResourceCollection 和 JsonResource。 https://laravel.com/docs/6.x/eloquent-resources#resource-responses
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\ResourceCollection;
class ShopCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}
对...
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class Shop extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}