Skip to content

Commit

Permalink
Merge pull request #397 from saloonphp/fix/multipart-value-on-single-…
Browse files Browse the repository at this point in the history
…value

Fix | Getting Single Multipart Value
  • Loading branch information
Sammyjo20 authored Apr 8, 2024
2 parents e669e85 + 6ceba63 commit 25cecb8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Repositories/Body/MultipartBodyRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ public function all(): array
*/
public function get(string|int $key, mixed $default = null): MultipartValue|array
{
$values = array_filter($this->all(), static function (MultipartValue $value) use ($key) {
$values = array_values(array_filter($this->all(), static function (MultipartValue $value) use ($key) {
return $value->name === $key;
});
}));

if (count($values) === 0) {
return $default;
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Body/MultipartBodyRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@
$body = new MultipartBodyRepository();

$body->add('name', 'Sam');
$body->add('friend', 'Chris');

expect($body->get('name'))->toEqual(new MultipartValue('name', 'Sam'));
expect($body->get('friend'))->toEqual(new MultipartValue('friend', 'Chris'));
});

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

0 comments on commit 25cecb8

Please sign in to comment.