-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[6.x] Use a map to prevent unnecessary array access #32296
[6.x] Use a map to prevent unnecessary array access #32296
Conversation
Thanks! 🎉 |
Originally we added arrayaccess onto entries etc to get it to work. That broke other stuff. Removed in 4903044e. This is the alternative. This can be removed if/when laravel/framework#32296 is merged and tagged.
@jasonvarga I guess this is an acceptable workaround, thanks for the pr. But like you said I again want to stress that resources are designed to work with Eloquent models so you could still run into problems at some point. |
I'm fine with taking that risk. The alternative would be to make our own nearly identical implementation. 😬 |
Seems to break my code
|
It break my code too with a kinda misleading error Had to replace |
@mholmes-hs @Shhu can one of you two please open up an issue and add full steps to reproduce? Please try to keep the code as minimal as possible to reproduce. |
@driesvints done with #32513 |
This works like a charm, thank you! |
I'm sure I'll get the "resources are an eloquent feature" response, but it's so great for us to use without needing to reinvent any wheels, and this is a tiny change so I thought it's worth a shot.
This change introduced a while back broke paginated API resources where people weren't using Eloquent models.
There are a bunch of issues #29858, #29916, #31703, #31704 (probably others) related to it.
This PR fixes the root cause for most of them. By changing from pluck to map, we avoid an array access call to the Eloquent model (or non-Eloquent model in our cases) that happens further down the stack trace. It'll let those of us who still want to use Resources to avoid ugly workarounds.