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

The use of JSON_FORCE_OBJECT flag when encoding props in blade template #5

Closed
nikazooz opened this issue Apr 5, 2019 · 1 comment
Closed

Comments

@nikazooz
Copy link

nikazooz commented Apr 5, 2019

Hey 👋 Awesome project and thanks for open-sourcing it!

I was just wondering, is there a particular reason for using JSON_FORCE_OBJECT flag on json_encode() in the blade template?

<div id="app" data-component="{{ $component }}" data-props="{{ json_encode($props, JSON_FORCE_OBJECT) }}"></

When fully loading f.e. contacts page, Vue shows prop validation errors as the links inside contacts prop is object because of it, and Pagination component expects it to be an array.

Thanks again. Cheers!

@reinink
Copy link
Member

reinink commented Apr 5, 2019

Good catch! I've fixed this: 1581692

I was using JSON_FORCE_OBJECT for situations where there are no props, json_encode() results in an empty array ([]), but Inertia expects an object ({}). The problem is JSON_FORCE_OBJECT doesn't only apply to the top level, but all nested data, which is not what we want. Simply casting the $props array to an object solves this.

<div id="app" data-component="{{ $component }}" data-props="{{ json_encode((object) $props) }}"></div>

@reinink reinink closed this as completed Apr 5, 2019
reinink pushed a commit that referenced this issue Apr 13, 2024
* Configure JIT mode

* Convert to Tailwind 3.0 colors

* Shift core Tailwind utilities

* Update Tailwind config

* Misc Tailwind upgrades

---------

Co-authored-by: Shift <shift@laravelshift.com>
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