Skip to content

Commit

Permalink
Ensure that list items are always returned as an array
Browse files Browse the repository at this point in the history
If an item has been removed then filter() will remove the null value
but preserve the keys of the remaining items. In JSON this will 
effectively turn the array into an object with keys.

Use values() to reset the keys.

Example: List with 3 items
Before: With entry 1 removed the remaining keys will be index 0 and 2.
After: With entry 1 remove the remaining keys will be 0 and 1.
  • Loading branch information
kasperg committed Jul 11, 2023
1 parent 8a6196f commit da0c241
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion app/Http/Controllers/v1/ListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected function getItems(Request $request, string $listId): array
} catch (\InvalidArgumentException $e) {
$this->log->error('Unable to process stored item id: ' . $e->getMessage());
}
})->filter()->toArray();
})->filter()->values()->toArray();
}

public function hasItem(Request $request, string $listId, ListItem $item): Response
Expand Down

0 comments on commit da0c241

Please sign in to comment.