Can someone explain the difference between a ResourceCollection and JsonResource?
In Laravel 6 docs you can generate 2 different types of resources... ResourceCollection and 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);
}
}
vs ...
<?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);
}
}