Fix behavior on automatic resource name setter

This commit is contained in:
Dane Everitt 2018-01-21 14:37:57 -06:00
parent 8dcab927e5
commit faaf27632c
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53

View file

@ -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();
}
}