Skip to content

Commit faaf276

Browse files
committed
Fix behavior on automatic resource name setter
1 parent 8dcab92 commit faaf276

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

app/Extensions/Spatie/Fractalistic/Fractal.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ public function createData()
3939
}
4040
}
4141

42+
if (is_null($this->resourceName) && $this->data instanceof LengthAwarePaginator) {
43+
$item = collect($this->data->items())->first();
44+
if ($item instanceof Model) {
45+
if (defined(get_class($item) . '::RESOURCE_NAME')) {
46+
$this->resourceName = constant(get_class($item) . '::RESOURCE_NAME');
47+
}
48+
}
49+
}
50+
4251
return parent::createData();
4352
}
4453
}

0 commit comments

Comments
 (0)