Skip to content

Commit 25cecb8

Browse files
authored
Merge pull request #397 from saloonphp/fix/multipart-value-on-single-value
Fix | Getting Single Multipart Value
2 parents e669e85 + 6ceba63 commit 25cecb8

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Repositories/Body/MultipartBodyRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ public function all(): array
127127
*/
128128
public function get(string|int $key, mixed $default = null): MultipartValue|array
129129
{
130-
$values = array_filter($this->all(), static function (MultipartValue $value) use ($key) {
130+
$values = array_values(array_filter($this->all(), static function (MultipartValue $value) use ($key) {
131131
return $value->name === $key;
132-
});
132+
}));
133133

134134
if (count($values) === 0) {
135135
return $default;

tests/Unit/Body/MultipartBodyRepositoryTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@
100100
$body = new MultipartBodyRepository();
101101

102102
$body->add('name', 'Sam');
103+
$body->add('friend', 'Chris');
103104

104105
expect($body->get('name'))->toEqual(new MultipartValue('name', 'Sam'));
106+
expect($body->get('friend'))->toEqual(new MultipartValue('friend', 'Chris'));
105107
});
106108

107109
test('you can get multiple items with the same name', function () {

0 commit comments

Comments
 (0)