我有以下函数,可以在用户通过电子邮件发送的URL注册后激活用户。
public function getActivate($code) {
$user = User::where('code', '=', $code)->where('active', '=', 0);
if($user->count()) {
$user = $user->first();
//Change user's active state
$user->active = 1;
$user->code = '';
if($user->save()) {
return Redirect::route('home')
->with('global', 'Activated! You can now sign in!');
}
}
return Redirect::route('home')
->with('global', 'We could not activate your account. Try again later.');
}
这是有效的,但现在我得到的只是这个错误:
Symfony Component Debug Exception FatalErrorException
Call to undefined method stdClass::save()
最新dev
版本中的错误。根据这个答案。该错误在任何稳定版本中都不存在。将composer.json
的minimum-stability
更改为stable
并运行作曲家更新。有关此线程的更多信息 Github
.
尝试在查询末尾附加 get 方法,以便返回集合。当你有集合(这是对象的Laravel集合)时,你将能够在该对象上调用方法。
我有非常相似的症状,但就我而言,问题出在表架构定义中:
$table->integer('my_id')->unsigned();
需要:
$table->increments('my_id')->unsigned();
我刚刚遇到了同样的问题但我无法按照 Alpha 的建议稳定@The因为它正在运行 React.js并且它需要一个开发版
所以这是我如何解决它
而不是
>>> $note->body = 'Some note for the card.';
=> "Some note for the card."
>>> $note->card_id = 2;
=> 2
>>> $note->save();
[SymfonyComponentDebugExceptionFatalThrowableError]
Call to undefined method stdClass::save()
这是我所做的
>>> $note = new AppNote;
=> AppNote {#640}
>>> $note->body = 'Some note for the card.';
=> "Some note for the card."
>>> $note->card_id = 2;
=> 2
>>> $note->save();
=> true
它奏效了!干杯