Skip to content

Commit

Permalink
simplify collection detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyvelnet committed Aug 14, 2017
1 parent 43edf16 commit 7002fd1
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/Cyvelnet/Laravel5Fractal/Traits/Transformable.php
Expand Up @@ -3,6 +3,7 @@
namespace Cyvelnet\Laravel5Fractal\Traits;

use League\Fractal\Pagination\PaginatorInterface;
use Illuminate\Pagination\AbstractPaginator as Paginator;

/**
* Trait Transformable.
Expand Down Expand Up @@ -116,12 +117,7 @@ public function transform($data, $transformer = null, $resourceKey = null, Pagin
*/
protected function getCollectionClass()
{
return [
'Illuminate\Support\Collection',
'Illuminate\Database\Eloquent\Collection',
'Illuminate\Pagination\LengthAwarePaginator',
'Illuminate\Pagination\Paginator',
];
return [];
}

/**
Expand Down Expand Up @@ -159,19 +155,17 @@ protected function getTransformerProperty()
*/
protected function isCollection($data)
{
if (is_array($data)) {
if (is_array($data) || $data instanceof \Illuminate\Support\Collection || $data instanceof Paginator) {
return true;
}

$length = count($this->getCollectionClass());

if ($length) {
for ($i = 0; $i < $length; $i++) {
$class = \Illuminate\Support\Arr::get($this->getCollectionClass(), $i);
for ($i = 0; $i < $length; $i++) {
$class = \Illuminate\Support\Arr::get($this->getCollectionClass(), $i);

if ($data instanceof $class) {
return true;
}
if ($data instanceof $class) {
return true;
}
}

Expand Down

0 comments on commit 7002fd1

Please sign in to comment.