Add database list endpoint, add more resource name magic

This commit is contained in:
Dane Everitt 2018-01-25 21:26:06 -06:00
parent 407120a854
commit 2bd691efad
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
36 changed files with 416 additions and 187 deletions

View file

@ -2,7 +2,7 @@
namespace Pterodactyl\Extensions\Spatie\Fractalistic;
use Illuminate\Database\Eloquent\Model;
use League\Fractal\TransformerAbstract;
use League\Fractal\Serializer\JsonApiSerializer;
use Spatie\Fractalistic\Fractal as SpatieFractal;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
@ -31,21 +31,14 @@ class Fractal extends SpatieFractal
$this->paginator = new IlluminatePaginatorAdapter($this->data);
}
// Automatically set the resource name if the response data is a model
// and the resource name is available on the model.
if (is_null($this->resourceName) && $this->data instanceof Model) {
if (defined(get_class($this->data) . '::RESOURCE_NAME')) {
$this->resourceName = constant(get_class($this->data) . '::RESOURCE_NAME');
}
}
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');
}
}
// 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();
}
return parent::createData();