laravel / framework

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

Markdown Email ErrorException - Undefined variable: subcopy #20617

Closed ghost closed 7 years ago

ghost commented 7 years ago

Description:

The 'subcopy' component in my Markdown template is throwing an ErrorException, but only in my production environment.

Steps To Reproduce:

I switched to using Markdown email in my Laravel app recently. In some of my markdown templates I've included "subcopy" components. Example of my Markdown template is here:


@component('mail::message')
    @component('mail::panel')
        panel content
    @endcomponent

    @component('mail::subcopy')
        subcopy content
    @endcomponent

    @component('mail::button', ['url' => $url])
        button text
    @endcomponent
@endcomponent 

When released to my production environment, I get the following error:

ErrorException: Undefined variable: subcopy (View: /var/www/vhosts/my.planetlabel.com/resources/views/vendor/mail/html/message.blade.php)

The same emails work fine on my development and staging environments, which for the most part mirror my production environment. I dont necessarily have to use the 'subcopy' component, but I am curious why it works fine on my development and staging environments, but not on my production environment.

themsaid commented 7 years ago

try to clear the views cache on your production server.

Lucassifoni commented 7 years ago

@lancemattson any chance you're running supervisor to process email jobs ?

When this error pops up, I run

php artisan cache:clear
php artisan clear-compiled
php artisan view:clear
supervisorctl reread
supervisorctl update
supervisorctl restart all

Rendering the views directly doesn't trigger an error, but supervisor has to be updated. I'll try to setup a test bench

ghost commented 7 years ago

@themsaid Clearing the views cache on my production server did not resolve the issue.

I actually ended up just removing the 'subcopy' component from all my email views. It wasnt a feature I absolutely needed.

@Lucassifoni I dont believe my production server is using 'supervisor' to process email jobs, but I will look into it and see if that could be the issue. Its good to hear that someone else has at least come across this error.

Thanks for your comments!

Lucassifoni commented 7 years ago

@lancemattson maybe not supervisor but anything using compiled views. This error only occurs after updates for me, and it seems that queue workers compile the jobs once and still use their version after a composer update or similar tinkering.

I only have limited comprehension of how those things are executed, I should dive into it instead of assuming this is the root cause.

I'll keep you updated if I ever encounter the cause of this precise issue !

themsaid commented 7 years ago

Closing for lack of activity and being unable to replicate, please ping me in case anybody else was able to replicate this issue.

shihabudheenf commented 6 years ago

I am getting same error.

QWp6t commented 6 years ago

@shihabudheenf it seems there's been difficulty reproducing the error. Can you provide a minimal, complete, and verifiable example?

shihabudheenf commented 6 years ago

@QWp6t it was my issue, I was upgraded application from 5.5 to 5.7, so 'or' depreciated and need to use '??' instead of that, i removed all 'or` code from mail template and now issue fixed.

alariva commented 6 years ago

Had same issue, as @shihabudheenf says, if after a Laravel upgrade to 5.7, it's about making sure all blade templates are up to date (or to ??) as per upgrading docs on blade section.

stevebauman commented 5 years ago

To elaborate on @alariva's solution, I had Laravel's mail templates published in my views directory (resources/views/vendor/mail). These were published prior to the 5.7 upgrade and they all contained the or syntax. Once I deleted them and re-published them I was back up and running.

djamesfar commented 4 months ago

I had this same error, and fixed it by changing in the mail layout: from: {{ $subcopy or '' }} to: {{ $subcopy ?? '' }}

Note that I had upgraded my laravel version from 5.x -> 6.0