From faaf27632cd6ca3102de37ed6a86fc21d7ff7558 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 21 Jan 2018 14:37:57 -0600 Subject: [PATCH] Fix behavior on automatic resource name setter --- app/Extensions/Spatie/Fractalistic/Fractal.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Extensions/Spatie/Fractalistic/Fractal.php b/app/Extensions/Spatie/Fractalistic/Fractal.php index cbe8f46b5..9ac0d588c 100644 --- a/app/Extensions/Spatie/Fractalistic/Fractal.php +++ b/app/Extensions/Spatie/Fractalistic/Fractal.php @@ -39,6 +39,15 @@ class Fractal extends SpatieFractal } } + if (is_null($this->resourceName) && $this->data instanceof LengthAwarePaginator) { + $item = collect($this->data->items())->first(); + if ($item instanceof Model) { + if (defined(get_class($item) . '::RESOURCE_NAME')) { + $this->resourceName = constant(get_class($item) . '::RESOURCE_NAME'); + } + } + } + return parent::createData(); } }