I have just upgraded my 5.2 install of laravel to 5.3 and then to 5.4 following the official upgrading methods.

I am now trying to use one of the new features, to create a markdown formated email.

According to the documentation found at: https://laravel.com/docs/5.4/mail#view-data

要嵌入内嵌图像,请在$message上使用嵌入方法

However, this:

<img src="{{ $message->embed(public_path().'/img/official_logo.png') }}">

将产生以下错误:

未定义变量:message

我错过什么了吗?或者升级指南中是否有未记录的内容?

稍后编辑:

I am calling the email function with:

\Mail::to($user)->send(new WelcomeCandidate($user, $request->input('password')));

候选人看起来像:

<?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->user = $user;
        $this->password = $password;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $this->subject('Welcome!');
        return $this->markdown('emails.welcome-candidate');
    }
}

推荐答案

It seems that the older $message->embed doesn't work nicely with Markdown emails. Like you mentioned in the comments it seems broken since 5.4

但是你可以像这样在你的markdown 邮箱中try 一下:

This is your logo 
![Some option text][logo]

[logo]: {{asset('/img/official_logo.png')}} "Logo"

如图所示:

Asset function reference: https://laravel.com/docs/5.4/helpers#method-asset

Laravel相关问答推荐

Laravel使用PostgreSQL显示";`try 读取null`上的属性,而不是SQL错误消息

Laravel FAKER语法

LARAVEL 从多个表中获取重复的行

Laravel:在行的子集上同步多对多

1 子编译中的警告(使用'stats.children:true'和'--stats-children'了解更多详细信息)

Laravel:使用 Input::old 时 textarea 不会重新填充

Eloquent的条件过滤器

Laravel 中间件 except除外规则不起作用

Laravel 中的合同和 PHP 中的接口有什么区别?

laravel 5 中的登录事件处理

计算laravel中查询返回的行数

在 Laravel 中将 Public 添加到assets资源路径

Guzzle 返回流空体而不是 json 体

Laravel Eloquent 多态一对一?

assets资源不引用公用文件夹(Laravel)

如何在 Laravel 5.2 中使用 OR 条件将多个参数传递给中间件

Laravel 5 事件处理程序未触发

如果在 Laravel 5.1 中找不到路由,则显示 404 页面

如何从 laravel 5.1 中数据库表的 created_at 属性中 Select 年份和月份?

Laravel 4 控制器模板/Blade - 正确的方法?