Bowis
Bowis

Reputation: 632

InvalidArgumentException : View [themes.] not found

I get the following error message out of the blue.

InvalidArgumentException : View [themes.] not found. Exception trace: 1 Illuminate\View\FileViewFinder::findInPaths("themes.") C:\xampp\htdocs\RoosterIKEA\vendor\laravel\framework\src\Illuminate\View\FileViewFinder.php:92 2 Illuminate\View\FileViewFinder::findNamespacedView("mail::themes.") C:\xampp\htdocs\RoosterIKEA\vendor\laravel\framework\src\Illuminate\View\FileViewFinder.php:76

Any idea which file this could be and what is going on?

Upvotes: 0

Views: 1991

Answers (1)

Salim Djerbouh
Salim Djerbouh

Reputation: 11044

In the class Illuminate\Mail\Markdown line 64

return new HtmlString(($inliner ?: new CssToInlineStyles)->convert(
    $contents, $this->view->make('mail::themes.'.$this->theme)->render()
));

It appears that $this->theme is an empty string

Now the class already defines the property on line 24

/**
 * The current theme being used when generating emails.
 *
 * @var string
 */
protected $theme = 'default';

Which means that you may have overridden this property by an empty string or maybe a null value in your markdown mailable

If you publish the components by

php artisan vendor:publish --tag=laravel-mail

You'll see a CSS file in resources/views/vendor/mail/html/themes named default.css

I found a way to reproduce this error on purpose to have a Mailable class like so

Run

php artisan make:mail OrderShipped --markdown=emails.orders.shipped

Then override the theme property by an empty string

<?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');
    }
}

Now send an email

use App\User;
use App\Mail\OrderShipped;

Route::get('/', function () {
    \Mail::to(User::first())->send(new OrderShipped());
});

And you would get the same error
enter image description here

The solution here is to either remove the protected $theme = ''; property or set it to default

I hope this helps

Upvotes: 2

Related Questions