Search code examples
laraveleloquentlaravel-5.3

Accessing Model properties as camel case in Laravel 5+


I would like to access database model properties in camelCase in my code, but store them as snake_case in my tables (as appears to be standard).

I've read that Eloquent will automatically convert between them on retrieving/saving, but that doesn't appear true.

One poor solution is to manually define the camel case version of each property, but then save() tries to write all properties to the table, creating column not found error.

Is the best solution to just use getters and setters for each property?

Is there any better way? Thank you!


Solution

  • If I understand your question correctly, this Laravel package should do what you need.

    https://github.com/kirkbushell/eloquence