I have existing data in a mysql db whose columns are camelCased. I can't change them to snake case.
For instance: when I try to use "jobRole", I get "job_role". I want it to be "jobRole".
Is there a setting in laravel to support this? I've read about mutators but don't understand them. Is that the solution? If so, how do I do this?
Discovered you can do this.
In the model, redefine "snakeAttributes" to "false" like this:
class YourModel extends Eloquent{
public static $snakeAttributes = false;
}
You can now. I've just completed a package that allows you to work with model attributes completely in camelCase, if required.
https://github.com/kirkbushell/eloquence
Install the package as per normal:
composer require kirkbushell/eloquence ~1.0
Then setup your service providers:
'KirkBushell\Eloquence\EloquenceServiceProvider',
Then all you need to do is either setup Eloquent to point to the new class as part of your aliases in application/config/app.php:
'Eloquent' => 'KirkBushell\Eloquence\Database\Model',
That ensures that the library is basically a drop-in replacement. If you want to just test with some models, you can simply extends the Eloquence base model class:
class MyModel extends \KirkBushell\Eloquence\Database\Model
I built this class mainly because I was sick of seeing snake_case in our javascript applications, but also in our server-side code. This ensured that everywhere (front-end and back-end) was dealing with camel casing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With