title: laravel 5.4 embed image in mail
body: <p>I have just upgraded my <code>5.2</code> install of laravel to <code>5.3</code> and then to <code>5.4</code> following the official upgrading methods.</p>
  
  <p>I am now trying to use one of the new features, to create a markdown formated email.</p>
  
  <p>According to the documentation found at: <a href="https://laravel.com/docs/5.4/mail#view-data" rel="noreferrer">https://laravel.com/docs/5.4/mail#view-data</a></p>
  
  <blockquote>
    <p>To embed an inline image, use the embed method on the <code>$message</code>
    variable within your email template. Laravel automatically makes the
    <code>$message</code> variable available to all of your email templates, so you
    don't need to worry about passing it in manually:</p>
  </blockquote>
  
  <p>However, this:</p>
  
  <pre><code>&lt;img src="{{ $message-&gt;embed(public_path().'/img/official_logo.png') }}"&gt;
  </code></pre>
  
  <p>will produce the following error:</p>
  
  <blockquote>
    <p>Undefined variable: <code>message</code></p>
  </blockquote>
  
  <p>Am I missing something? Or is there something undocumented in the upgrading guides?</p>
  
  <p>Later edit:</p>
  
  <p>I am calling the email function with:</p>
  
  <p><code>\Mail::to($user)-&gt;send(new WelcomeCandidate($user, $request-&gt;input('password')));</code></p>
  
  <p>And WelcomeCandidate looks like:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Mail;
  
  use Illuminate\Bus\Queueable;
  use Illuminate\Mail\Mailable;
  use Illuminate\Queue\SerializesModels;
  use Illuminate\Contracts\Queue\ShouldQueue;
  
  use App\Models\User;
  
  class WelcomeCandidate extends Mailable
  {
  
      use Queueable, SerializesModels;
  
      public $user;
      public $password;
  
      /**
       * Create a new message instance.
       *
       * @return void
       */
      public function __construct(User $user, $password)
      {
          //
          $this-&gt;user = $user;
          $this-&gt;password = $password;
      }
  
      /**
       * Build the message.
       *
       * @return $this
       */
      public function build()
      {
          $this-&gt;subject('Welcome!');
          return $this-&gt;markdown('emails.welcome-candidate');
      }
  }
  </code></pre>