简体   繁体   English

如果表列的名称为大写,如何创建访问器和变量

[英]How to create accessors and mutators if table column's name is uppercase

I'm using Laravel 4.2 in my project, how can I create accessors and mutators for my model, if database column's name pattern is like this: 我在项目中使用Laravel 4.2,如果数据库列的名称模式如下所示,如何为模型创建accessors mutatorsmutators

| ABC_ID |  ABC_DAT_JAN | ABC_DAT_FEV | ABC_DAT_MAR | ABC_DAT_ABR |
| 1      |  12          | 10          | 20          | 13          |

I created the function getAbcDatJanAttribute($value) , but it's not working, expected, I think it try to get the attribute abc_dat_jan . 我创建了函数getAbcDatJanAttribute($value) ,但是不能正常工作,我想它会尝试获取属性abc_dat_jan

How can I create accessors abd mutators in this case? 在这种情况下,如何创建accessors abd mutators

Laravel looks for accessors and mutators by converting the first letter of each word in the column name to uppercase and removing any - or _ . Laravel寻找accessorsmutators把每个单词的第一个字母的列名大写和删除任何-或者_

Since everything is uppercase for you, you can use getABCDATJANAttribute($value) instead. 由于所有内容都是大写的,因此可以改用getABCDATJANAttribute($value)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM