【发布时间】:2014-10-09 23:15:27
【问题描述】:
我有模型
用户
在保存时对每条记录执行 touchOwners。
<?php
class User extends Eloquent {
protected $touches = array('userDesk');
[...]
}
当我要新建一条记录时,问题来了:eloquent 尝试去触摸一个相关表中不存在的字段(既然用户是新创建的,那怎么会有一条记录引用给相关表中的这个用户?!?...)。
如何暂时禁用此功能以允许我创建新用户而不会引发异常:
调用未定义的方法 Illuminate \ Database \ Eloquent \ Collection :: touchOwners()
?
我试过这个:
$user->setTouchedRelations(array());
但当然它没有用......
【问题讨论】:
-
of course it did not work是什么意思?这正是您所需要的。