laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.47k stars 11.01k forks source link

After changing theme in Mailable class for particular email it messed up other email in system #48095

Closed jigarhalani closed 1 year ago

jigarhalani commented 1 year ago

Laravel Version

9.31

PHP Version

8.1.12

Database Driver & Version

No response

Description

Hello,

I have situation where i need to send one email from different theme also from different resource path so I override Mailable class to TablerMailable class and changed theme and components like below.

<?php

namespace App\Support;

use Illuminate\Bus\Queueable;
use Illuminate\Container\Container;
use Illuminate\Contracts\View\Factory as ViewFactory;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Markdown;
use Illuminate\Queue\SerializesModels;

class TablerMailable extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Instruct to use tabler theme.
     *
     * @var string
     */
    public $theme = 'tabler';

    /**
     * Build the Markdown view for the message.
     *
     * @return array
     */
    protected function buildMarkdownView()
    {
        // $view = Container::getInstance()->make(ViewFactory::class);
        // $view->addNamespace('tabler-mail', [resource_path('views/vendor/tabler-mail')]);
        $markdown = Container::getInstance()->make(Markdown::class);
        // Can override paths like this, since Markdown instance is singleton.
        $markdown->loadComponentsFrom([resource_path('views/vendor/tabler-mail')]);
        if (isset($this->theme)) {
            $markdown->theme($this->theme);
        }

        $data = $this->buildViewData();

        $views= [
            'html' => $markdown->render($this->markdown, $data),
            'text' => $this->buildMarkdownText($markdown, $data),
        ];

        return $views;
    }
}

in my one email I am extending this class object so that email go from the new email library. but for other old it should not change theme or anything.

but right now whenever my email go using this new TablerMailable class other email also getting messed up in that queue until I don't run php artisan view:clear something is getting cached which cause error in other email which extend directly laravel Mailable class

Steps To Reproduce

  1. create TablerMailable class as i mentioned above
  2. send email in queue using this class
  3. send other email in same queue using laravel default mailable class.
  4. now check other email which sent from Mailable class which is completely messedup.
driesvints commented 1 year ago

Hey there,

Unfortunately we don't support this version anymore. Please check out our support policy on which versions we are currently supporting. Can you please try to upgrade to the latest version and see if your problem persists? If so, please open up a new issue and we'll help you out.

Thanks!