简体   繁体   中英

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:

| 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 .

How can I create accessors abd mutators in this case?

Laravel looks for accessors and mutators by converting the first letter of each word in the column name to uppercase and removing any - or _ .

Since everything is uppercase for you, you can use getABCDATJANAttribute($value) instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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