kirkbushell / eloquence

A drop-in library for certain database functionality in Laravel, that allows for extra features that may never make it into the main project.
MIT License
537 stars 58 forks source link

Camelcase conflict with getAttribute #26

Closed Zyles closed 8 years ago

Zyles commented 8 years ago

Hi,

I put the trait in my User model and get error:

Fatal error: Method 'getAttribute' declared in multiple traits in 

I also use these:

use Authenticatable, CanResetPassword, Metable, Rememberable, CamelCaseModel;

What to do?

Thanks.

Zyles commented 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?

kirkbushell commented 8 years ago

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.