InvalidArgumentException:未找到[主题。]

问题描述 投票:0回答:1

我突然得到以下错误消息。

InvalidArgumentException:未找到视图[主题。]。异常跟踪:1 Illuminate \ View \ FileViewFinder :: findInPaths(“ themes。”)C:\ xampp \ htdocs \ RoosterIKEA \ vendor \ laravel \ framework \ src \ Illuminate \ View \ FileViewFinder.php:922 Illuminate \ View \ FileViewFinder :: findNamespacedView(“ mail :: themes。”)C:\ xampp \ htdocs \ RoosterIKEA \ vendor \ laravel \ framework \ src \ Illuminate \ View \ FileViewFinder.php:76

任何想法这可能是哪个文件以及正在发生什么事情?

laravel
1个回答
1
投票

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';

这意味着您可能已在可邮寄的减价商品中用空字符串或空值覆盖了此属性

如果您通过]发布组件>

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());
});

您会得到相同的错误enter image description here

这里的解决方案是删除protected $theme = '';属性或将其设置为default

我希望这会有所帮助

© www.soinside.com 2019 - 2024. All rights reserved.