问题
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