inertiajs / inertia-laravel

The Laravel adapter for Inertia.js.
https://inertiajs.com
MIT License
2.03k stars 227 forks source link

Can we make `render` support `JsonSerializable`? #526

Open simensen opened 1 year ago

simensen commented 1 year ago

Even though I'm using Laravel, not all objects I'm passing as props are aware of Arrayable. In some cases, I'd like to be able to keep my objects closer to "pure PHP" and implement JsonSerializable. Given the nature of props ultimately being serialized to JSON anyway, this seems like a logical type to accept as a prop.

I'm happy to implement this, but I want to make sure I am correct that this makes sense and that the Inertia team wouldn't rather have this handled or implemented some other way. :)


My story:

I just lost time trying to figure out why the data I was sure I was saving wasn't being passed to the frontend correctly (always an empty object). It turns out my data was being selected and sent correctly. It's just that my generic Collection implementation implements JsonSerializable and not Arrayable so it was being "serialized to JSON" as an empty object.