Search code examples
phplaraveleloquentlaravel-3

Laravel Eloquent: Name attributes and db rows differently


I've just started to create an application using the Laravel framework for the first time.

Eloquent seems to be a very powerful and code-saving tool, but I can't figure out how to use different attribute names in the model than in the database table.

Here my conflict:

Database: iddog, dtname, dtbirth, dtfoo, fimom, fidad
Attributes: id, name, birth, foo, mom, dad

Is there a possibility to do that in a model that extends from Eloquent in the Laravel framework? Naming attributes differently than the associated database fields?

Or isn't it cool anymore to call fields in a database table like I do here?

Thank's in advance!


Solution

  • Why have different names for the database to your model?

    Although you can do it - your just creating work for yourself, and introducing possible new bugs. Just use the database names.

    If you must - check out Getters & Setters.