title: Laravel Mailer queue with Redis showing error "The script tried to execute a method or access a property of an incomplete object."
body: <p>This is the complete error. </p>
  
  <blockquote>
    <p><strong>Illuminate\Mail\SendQueuedMailable::handle()</strong>: The script tried to
    execute a method or access a property of an incomplete object. Please
    ensure that the class definition "Security\Mail\WelcomeMail" of the
    object you are trying to operate on was loaded before unserialize()
    gets called or provide an autoloader to load the class definition in
    /var/www/html/vendor/laravel/framework/src/Illuminate/Mail/SendQueuedMailable.php</p>
  </blockquote>
  
  <p>We are using Laravel 5.5. And executing the following code</p>
  
  <pre><code>Mail::to($customer)-&gt;queue(new WelcomeMail($customer));
  </code></pre>
  
  <p>The mailer is the default mailer that comes with laravel, but we're queueing jobs to redis. Customer is a User object. The WelcomeMail is the following</p>
  
  <pre><code>use Illuminate\Bus\Queueable;
  use Illuminate\Contracts\Queue\ShouldQueue;
  use Illuminate\Mail\Mailable;
  use Illuminate\Queue\SerializesModels;
  
  class WelcomeMail extends Mailable implements ShouldQueue
  {
      use Queueable, SerializesModels;
  
      public $user;
  
      /**
       * Create a new message instance.
       *
       * @return void
       */
      public function __construct($user)
      {
          $this-&gt;user = $user;
      }
  
      /**
       * Build the message.
       *
       * @return $this
       */
      public function build()
      {
          return $this-&gt;view('security::emails.welcome');
      }
  }
  </code></pre>