在课堂Illuminate\Mail\Markdown第64行
return new HtmlString(($inliner ?: new CssToInlineStyles)->convert(
$contents, $this->view->make('mail::themes.'.$this->theme)->render()
));
$this->theme 似乎是一个空字符串
现在该类已经在第 24 行定义了属性
/**
* The current theme being used when generating emails.
*
* @var string
*/
protected $theme = 'default';
这意味着你可能已经用一个空字符串或者你的 markdown mailable 中的一个空值覆盖了这个属性
如果您通过
发布组件
php artisan vendor:publish --tag=laravel-mail
您将在 resources/views/vendor/mail/html/themes 中看到一个名为 default.css 的 CSS 文件
我找到了一种方法来重现此错误,以便有一个像这样的 Mailable 类
运行
php artisan make:mail OrderShipped --markdown=emails.orders.shipped
然后用空字符串覆盖主题属性
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class OrderShipped extends Mailable
{
use Queueable, SerializesModels;
protected $theme = ''; // <--- HERE
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->markdown('emails.orders.shipped');
}
}
现在发送电子邮件
use App\User;
use App\Mail\OrderShipped;
Route::get('/', function () {
\Mail::to(User::first())->send(new OrderShipped());
});
你会得到同样的错误
这里的解决方案是删除 protected $theme = ''; 属性或将其设置为 default
希望对你有帮助