Closed Zyles closed 8 years ago
I forgot to extend Eloquence model which solved it. But that brought me to another issue. What about models that I do not directly control? For example the metable package holds its own models in the vendor dir. And the pagination from Eloquent.
Example JSON:
{
"result": {
"total": 2,
"per_page": 100,
"current_page": 1,
"last_page": 1,
"next_page_url": null,
"prev_page_url": null,
"from": 1,
"to": 2,
"data": [
{
"id": "1",
"email": "admin@example.com",
"username": "admin",
"firstname": "Super",
"lastname": "Admin",
"active": "1",
"blocked": "0",
"blockedMessage": null,
"createdAt": "2015-09-03 21:09:15",
"updatedAt": "2015-09-03 21:09:15",
"meta_data": []
},
{
"id": "2",
"email": "manager@example.com",
"username": "manager",
"firstname": "System",
"lastname": "Manager",
"active": "1",
"blocked": "0",
"blockedMessage": null,
"createdAt": null,
"updatedAt": null,
"meta_data": []
}
]
},
"statusCode": 200,
"fromCache": true
}
I'd like to camel these too.
Wouldn't it be better to apply camelcase on a full response basis rather than model?
There's nothing you can do about other models. Technically I wouldn't be using models from packages anyway. They're meant to represent business concerns and that's not something you can generally outsource away.
However, I do agree with your last sentence. Having some sort of JSON view presenter is certainly another approach you can take for those models that aren't touched by Eloquence.
Hi,
I put the trait in my User model and get error:
I also use these:
What to do?
Thanks.