Laravel雄辩模特的临时财产 [英] Temporary property for Laravel Eloquent model
问题描述
当我添加这个属性并点击$ user-> save()我得到一个错误,说我没有数据库列安全。在保存之前,我可以解决安全问题,但是不知何故,应该有更好的方法来做到这一点。任何建议?
只需添加一个属性到您的课堂。
class User Eloquent {
public $ secure;
// ...
}
请注意更好地声明它受保护,并添加相应的访问器和变异器( getSecure
和 setSecure
方法)到你的模型。 p>
I have a Laravel Eloquent model User, which has a table with username and email columns. I need to add a property for the model on runtime, something like $user->secure. This property doesn't need to go to database.
When i add this property and hit $user->save() i get an error saying i don't have database column 'secure'. I can unset 'secure' before save but somehow it feels there should be a better way to do so. Any suggestions?
Just add an attribute to your class.
class User extends Eloquent {
public $secure;
// ...
}
Note that it is better to declare it protected and add corresponding accessors and mutators (getSecure
and setSecure
methods) to your model.
这篇关于Laravel雄辩模特的临时财产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!