【发布时间】:2014-12-17 17:16:17
【问题描述】:
我正在尝试这样做:
$volunteer = Volunteer::with('user')->find($id);
$input = $updateVolunteerRequest->all();
$volunteer->fill($this->fillFields($input));
$volunteer->user->fill([
'email' => $input['email']
]);
$volunteer->push();
但push() 方法似乎不起作用。
它会抛出以下错误:
FatalErrorException in Model.php line 1463:
Call to a member function push() on a non-object
It worked in Laravel 4. Is there a new way of doing this in version 5? Or am I doing something wrong.
我检查了$volunteer,它返回了模型。
【问题讨论】:
-
您可能会发现以下答案很有用:stackoverflow.com/questions/24303003/…
-
填充方法在我的情况下有效
-
@aBhijit 我已经更新了我的答案,其中包含指向我刚刚提交的拉取请求的链接以更正问题。我不知道它是否会被接受,但您可以查看它以了解当前的解决方案或了解更多信息。
-
@aBhijit 我的 pull request 被合并进来了,所以如果你将 Laravel 更新到最新版本,这个问题应该会得到解决。
标签: php laravel laravel-5 eloquent model-associations