本文介绍了我可以用Laravel 4雄心勃勃地使用camelCase吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个mysql数据库中现有的数据,其列为camelCased。例如:当我尝试使用jobRole时,我得到job_role。我想要它是jobRole。



在laravel中是否有一个设置来支持?我已经看过关于mutator但是不了解它们。那是解决方案吗?如果是这样,我该怎么做?

解决方案

发现你可以这样做。



在模型中,将snakeAttributes重新定义为false,如下所示:

  class YourModel extends Eloquent {
public static $ snakeAttributes = false;
}


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;
}

这篇关于我可以用Laravel 4雄心勃勃地使用camelCase吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 04:37