Eloquent属性类型转换在某些模型中不起作用

时间:2015-10-08 16:28:50

标签: laravel casting eloquent lumen

Eloquent属性转换非常棒,这是从DB类型转换为本机语言类型很有用的强大功能。
我的数据库中的布尔值为from pymel.core import * import pymel.core as pm win = window(title="Camera Information", w=300, h=100) layout = columnLayout() text("Field of View") txtFl = textField() pm.separator( height=10, style='double' ) text("F-Stop") txtAv = textField() pm.separator( height=10, style='double' ) btn = button(label="Fetch Data", parent=layout) def fetchAttr(*args): camSel = listRelatives(ls(sl=True), ad=True) camSel = ls(camSel, type='camera') camAttr = camSel[0] cam = general.PyNode(camAttr) txtAv.setText(cam.fs.get()) txtFl.setText(cam.fl.get()) btn.setCommand(fetchAttr) win.show() ,因此我需要将其转换为int(1)类型。

我的应用程序中有几个模型,第一个模型是bool,它就像一个魅力 将1转换为true,将0转换为false,就像我需要的那样。

User

这里的一切都没问题,但我需要在另一个模型class User extends Model { protected $table = 'user'; protected $guarded = ['password','login','id','activationEmail']; protected $hidden = [ 'password' ]; protected $casts = [ 'activationEmail' => 'boolean', 'activationSMS' => 'boolean', ]; 中做同样的技巧。

NewsArticle

但是在这种情况下,强制转换根本不起作用,我试图手动投射并且它可以工作,但是铸造数组完全被忽略了。

有什么想法可以解决问题吗?

感谢。

1 个答案:

答案 0 :(得分:0)

抱歉,我的类模型的文件名出错了,但是类名本身是正确的,并且因为我为完成另一项任务所做的一些使用bootstrap文件的技巧而成功加载。 文件重命名后,一切都按预期工作。