From f8db60430d4b811f8ab771d25ec23b1c70edd302 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 23 Aug 2017 16:37:28 -0500 Subject: [PATCH] collect is optional --- .../Http/Resources/CollectsResources.php | 6 +++--- .../Resources/UnknownCollectionException.php | 21 ------------------- 2 files changed, 3 insertions(+), 24 deletions(-) delete mode 100644 src/Illuminate/Http/Resources/UnknownCollectionException.php diff --git a/src/Illuminate/Http/Resources/CollectsResources.php b/src/Illuminate/Http/Resources/CollectsResources.php index a394948b0772..6078e5f8f1ca 100644 --- a/src/Illuminate/Http/Resources/CollectsResources.php +++ b/src/Illuminate/Http/Resources/CollectsResources.php @@ -16,7 +16,9 @@ trait CollectsResources */ protected function collectResource($resource) { - $this->collection = $resource->mapInto($this->collects()); + $this->collection = ($collects = $this->collects()) + ? $resource->mapInto($collects) + : $resource->toBase(); return $resource instanceof AbstractPaginator ? $resource->setCollection($this->collection) @@ -38,8 +40,6 @@ protected function collects() class_exists($class = Str::replaceLast('Collection', '', get_class($this)))) { return $class; } - - throw new UnknownCollectionException($this); } /** diff --git a/src/Illuminate/Http/Resources/UnknownCollectionException.php b/src/Illuminate/Http/Resources/UnknownCollectionException.php deleted file mode 100644 index 126146a59a90..000000000000 --- a/src/Illuminate/Http/Resources/UnknownCollectionException.php +++ /dev/null @@ -1,21 +0,0 @@ -