Laravel 5.3 Error : Creating default object from empty value
<p>The code below has an error. I am using Laravel 5.3 and php 7.0.</p>

<p>I google it but still not clear, any help would be greatly appreciated.   </p>

<p><strong>ActivationService.php</strong></p>

<pre><code>&lt;?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-&gt;mailer = $mailer;
        $this-&gt;activationRepo = $activationRepo;
    }

    public function sendActivationMail($user)
    {

        if ($user-&gt;activated || !$this-&gt;shouldSend($user)) {
            return;
        }

        $token = $this-&gt;activationRepo-&gt;createActivation($user);

        $link = route('user.activate', $token);
        $message = sprintf('Activate account &lt;a href="%s"&gt;%s&lt;/a&gt;', $link, $link);

        $this-&gt;mailer-&gt;raw($message, function (Message $m) use ($user) {
            $m-&gt;to($user-&gt;email)-&gt;subject('Activation mail');
        });


    }

    public function activateUser($token)
    {
        $activation = $this-&gt;activationRepo-&gt;getActivationByToken($token);

        if ($activation === null) {
            return null;
        }

        $user = User::find($activation-&gt;user_id);
        //Below is line 53.
        $user-&gt;activated = true;

        $user-&gt;save();

        $this-&gt;activationRepo-&gt;deleteActivation($token);

        return $user;

    }

    private function shouldSend($user)
    {
        $activation = $this-&gt;activationRepo-&gt;getActivation($user);
        return $activation === null || strtotime($activation-&gt;created_at) + 60 * 60 * $this-&gt;resendAfter &lt; time();
    }

}
</code></pre>

<p><strong>Error message</strong></p>

<blockquote>
  <p>ErrorException in ActivationService.php line 53: Creating default object from empty value</p>
</blockquote>

<p>Line 53 of the code above is like this:</p>

<pre><code>$user-&gt;activated = true;
</code></pre>

<p>How could I settle the issue?   </p>