Replies: 4 comments
-
Hi @anthonymf, Why not just rename the column in db? 🤔 Column names should be easy to understand on both frontend and backend. |
Beta Was this translation helpful? Give feedback.
-
@alexzarbn Renaming the db column would not suit use cases where the DB is tightly coupled to other systems or other existing code in the Laravel application. But I think the principle of Laravel API Resources is that they allow fields in JSON responses to be aliased in the response, rather than having to do this in the database. This neatly decouples the API responses from the db structure. |
Beta Was this translation helpful? Give feedback.
-
@anthonymf Okay, that makes sense. I think introducing a method |
Beta Was this translation helpful? Give feedback.
-
@alexzarbn Yes, that sounds like a good plan. |
Beta Was this translation helpful? Give feedback.
-
Laravel API resources provide the ability to alias database fields in the JSON response, e.g.
And Laravel Orion provides Filters which expose the raw database fields, e.g.
But this means that the frontend developer has a "nice" name in the JSON response but must use a "raw" database field name in the filter.
So it would be helpful to the frontend developer if it was possible to expose
filterableBy
attributes via an alias, e.g.Does this suggestion make sense? Or is there a better way?
Beta Was this translation helpful? Give feedback.
All reactions