From 3d14974d643ef603237b25727ea6f1afb8c37b1f Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 7 Aug 2021 15:06:00 -0700 Subject: [PATCH] Correctly set the resource name on empty transformers --- app/Extensions/Spatie/Fractalistic/Fractal.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/Extensions/Spatie/Fractalistic/Fractal.php b/app/Extensions/Spatie/Fractalistic/Fractal.php index b9c651d3..3a708b73 100644 --- a/app/Extensions/Spatie/Fractalistic/Fractal.php +++ b/app/Extensions/Spatie/Fractalistic/Fractal.php @@ -2,8 +2,8 @@ namespace Pterodactyl\Extensions\Spatie\Fractalistic; -use League\Fractal\TransformerAbstract; use Spatie\Fractal\Fractal as SpatieFractal; +use Pterodactyl\Transformers\Api\Transformer; use Illuminate\Contracts\Pagination\LengthAwarePaginator; use League\Fractal\Pagination\IlluminatePaginatorAdapter; use Pterodactyl\Extensions\League\Fractal\Serializers\PterodactylSerializer; @@ -33,12 +33,9 @@ class Fractal extends SpatieFractal // If the resource name is not set attempt to pull it off the transformer // itself and set it automatically. - if ( - is_null($this->resourceName) - && $this->transformer instanceof TransformerAbstract - && method_exists($this->transformer, 'getResourceName') - ) { - $this->resourceName = $this->transformer->getResourceName(); + $class = is_string($this->transformer) ? new $this->transformer : $this->transformer; + if (is_null($this->resourceName) && $class instanceof Transformer) { + $this->resourceName = $class->getResourceName(); } return parent::createData();