Skip to content

Conversation

@nuernbergerA
Copy link
Contributor

@nuernbergerA nuernbergerA commented Nov 6, 2020

Hey guys.

If you map over an eloquent collection and return an array instead of a model you will receive a support collection.

But if you use mapWithKeys it will lead to errors.

If you try to serialize, it will explode in the sky because of this check.

I noticed map has a custom implementation on the eloquent collection to I added one for mapWithKeys with the same behavior.

I didn't extract the code to check and decide which collection type to return, to keep this PR light.

Also noticed there is a mapToDictionary, should we handle this too?

Have a nice day
Adrian

@driesvints
Copy link
Member

Ping @JosephSilber

@JosephSilber
Copy link
Contributor

JosephSilber commented Nov 9, 2020

  1. I was never a fan of returning a support collection from map. It leads to unexpected results (this just being one of many) and is just a losing proposition. We'll be chasing our tail forever on this futile endeavor.

  2. That said, if we still decide for some reason to keep doing this dance, then of course mapWithKeys needs to work the same way map does.

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.

4 participants