Example of Collection Methods: Transform in opendialogai/opendialog

File app/Http/Resources/ConversationCollection.php (link to Github)
use Illuminate\Http\Resources\Json\ResourceCollection;
use OpenDialogAi\ConversationBuilder\Conversation;

class ConversationCollection extends ResourceCollection
{
    public function toArray($request)
    {
        $this->collection->transform(function (ConversationResource $c) {
            return new ConversationBuilderResource($c->resource);
        });
        return parent::toArray($request);
    }
}