how can I use exists column with laravel model

本秂侑毒 提交于 2020-01-05 07:50:13

问题


I have a column in my database called exists, but when I try to use

$model->exists

Laravel checks if the record exists rater return the value of exists.

Is their any way to tell Laravel not to do this on that particular model?


回答1:


As suggested earlier, renaming your column would be a good idea, because it's a reserved keyword in most database servers.

To answer your question though, you can use $model->getAttribute('exists') to get the value of a model attribute.

Source




回答2:


There's another way to do this as well; set a variable to the name of your field, then access it this way:

$fieldname = 'exists'; $model->$fieldname;



来源:https://stackoverflow.com/questions/42341096/how-can-i-use-exists-column-with-laravel-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!