inertia-laravel icon indicating copy to clipboard operation
inertia-laravel copied to clipboard

Can we make `render` support `JsonSerializable`?

Open simensen opened this issue 1 year ago • 0 comments

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.

simensen avatar Jun 12 '23 16:06 simensen