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

Lazy loaded Arrayable props are no longer converted to array in v2.0 #716

Open
netpok opened this issue Feb 14, 2025 · 1 comment
Open

Comments

@netpok
Copy link

netpok commented Feb 14, 2025

In v2 Arrayable props are only converted to arrays if they are "regular" props. This happens because closures are resolved later than arrayable props: see here

IMHO this conversion should happen either on all forms of prop definition or never.

One solution would be to move resolveArrayableProperties after resolvePropertyInstances, this solves this issue but I did not test the effects on the whole system.


Backstory:

We use spatie media library in our project and passed the MediaCollection directly to the inertia view. After the v2 upgrade we noticed that ['propname' => $collection] and ['propname' => fn () => $collection] behaves differently.

This happens because

  • ['propname' => $collection] calls toArray because of the Arrayable check but
  • ['propname' => fn () => $collection] is not doing this so it will be fall back to toJson in the end which has a different implementation.
@pascalbaljet
Copy link

pascalbaljet commented Feb 14, 2025

See also #696 and #706

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

No branches or pull requests

2 participants