Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

panthro's avatar

Where To Format?

I'm using Laravel, with Api Resources and Inertia.

I need to format some of my data, for example date formatting for humans.

I considered doing it JS side, but as the same data appears in several places I want consistency.

So where to put it? Model accessor? Api Resource? Somewhere else?

Not, I cannot overwrite the original value, as I still need to retain it (for the date example, it may need editing by the user).

0 likes
2 replies
MohamedTammam's avatar

I would add the date and formatted date values in the API resources.

1 like
DhPandya's avatar

@panthro Using model accessor for it will be the good choice. It will help you to get rid from the additional formatting for all resource classes.

1 like

Please or to participate in this conversation.