Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.6] Add tests for the way JsonResource handles numeric keys #25226

Closed
wants to merge 1 commit into from
Closed

[5.6] Add tests for the way JsonResource handles numeric keys #25226

wants to merge 1 commit into from

Conversation

SjorsO
Copy link
Contributor

@SjorsO SjorsO commented Aug 16, 2018

JsonResource seems to strip all array keys if any of them are numeric or a numeric string. I couldn't find any tests that assert this behavior, so this PR adds some.

Because of this behavior, doing this will give you an array of names, without any ids:

public function index()
{
    $data = User::pluck('name', 'id');

    return JsonResource::make($data);
}

I'm not sure if this is a bug or a feature, but having tests for behavior like this is important.

@GrahamCampbell GrahamCampbell changed the title add tests for the way JsonResource handles numeric keys [5.6] Add tests for the way JsonResource handles numeric keys Aug 16, 2018
@deleugpn
Copy link
Contributor

deleugpn commented Aug 17, 2018

If there was no test for this before, perhaps we can try to fix it and target 5.7 instead of define it as the desired behavior?

@SjorsO
Copy link
Contributor Author

SjorsO commented Aug 17, 2018

These tests are defining it as the current behavior, they help prevent any unintended backward compatibility breaks.

I think it would be best if JsonResource matches the way json_encode() strips keys.

@taylorotwell
Copy link
Member

Send to 5.7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants