코드는 다음과 같습니다.
ActivationService.php
<code> <?php namespace App; use Illuminate\Mail\Mailer; use Illuminate\Mail\Message; class ActivationService { protected $mailer; protected $activationRepo; protected $resendAfter = 24; public function __construct(Mailer $mailer, ActivationRepository $activationRepo) { $this->mailer = $mailer; $this->activationRepo = $activationRepo; } public function sendActivationMail($user) { if ($user->activated || !$this->shouldSend($user)) { return; } $token = $this->activationRepo->createActivation($user); $link = route('user.activate', $token); $message = sprintf('Activate account <a href="%s">%s</a>', $link, $link); $this->mailer->raw($message, function (Message $m) use ($user) { $m->to($user->email)->subject('Activation mail'); }); } public function activateUser($token) { $activation = $this->activationRepo->getActivationByToken($token); if ($activation === null) { return null; } $user = User::find($activation->user_id); //下面这行是53行. $user->activated = true; $user->save(); $this->activationRepo->deleteActivation($token); return $user; } private function shouldSend($user) { $activation = $this->activationRepo->getActivation($user); return $activation === null || strtotime($activation->created_at) + 60 * 60 * $this->resendAfter < time(); } }</code>
오류 메시지:
<code> ErrorException in ActivationService.php line 53: Creating default object from empty value</code>
코드 53행에 주석이 있는데 코드는 $user->activated = true;
입니다.
질문:
위 코드는 이 오류를 어떻게 해결합니까?