Skip to content

Commit 959f1d7

Browse files
committed
Ensure data is serialized as array
Due to filtering, the data might end up as an object like this: ``` { 1: { ... }, 2: { ... } } ``` In Javascript this breaks because, for instance, `forEach` cannot be used on an object. Using `values()` ensures the output is serialized as a strict array.
1 parent f837301 commit 959f1d7

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Http/Controllers/ImportController.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public function getAvailableFieldsForImport(String $resource, $request)
5454
$novaResource = new $resource(new $resource::$model);
5555
$fieldsCollection = collect($novaResource->creationFields($request));
5656

57-
if (method_exists($novaResource, 'excludeAttributesFromImport')) {
58-
$fieldsCollection = $fieldsCollection->filter(function(Field $field) use ($novaResource, $request) {
57+
if (method_exists($novaResource, 'excludeAttributesFromImport')) {
58+
$fieldsCollection = $fieldsCollection->filter(function(Field $field) use ($novaResource, $request) {
5959
return !in_array($field->attribute, $novaResource::excludeAttributesFromImport($request));
6060
});
6161
}
@@ -67,7 +67,9 @@ public function getAvailableFieldsForImport(String $resource, $request)
6767
];
6868
});
6969

70-
return [$novaResource->uriKey() => $fields];
70+
// Note: ->values() is used here to avoid this array being turned into an object due to
71+
// non-sequential keys (which might happen due to the filtering above.
72+
return [$novaResource->uriKey() => $fields->values()];
7173
}
7274

7375
public function getAvailableResourcesForImport(NovaRequest $request) {

0 commit comments

Comments
 (0)