简体   繁体   English

Email Blade Got Undefined 变量:使用 Laravel 队列时

[英]Email Blade Got Undefined variable: when using Laravel queue

I tried to queue successful email whenever someone place new order on my website.每当有人在我的网站上下新订单时,我都会尝试排队成功的 email。 I used event and listener to accomplish this.我使用事件和侦听器来完成此操作。 Below is my code for sending the email on listener file:下面是我在监听器文件上发送 email 的代码:

NewOrderListener.php NewOrderListener.php

 public function handle($event)
    {
        try {
            dump('new order registered (listernerrr)');
    
            $email = $event->order['email'];
            
            Mail::send('email.order_mail_customer', $event->order, function($message) use($email)
            {
                dump($email);
                $sub_data = (Lang::has(Session::get('front_lang_file').'.FRONT_ORDER_SUCCSESS')) ? trans(Session::get('front_lang_file').'.FRONT_ORDER_SUCCSESS') : trans($this->FRONT_LANGUAGE.'.FRONT_ORDER_SUCCSESS');

                dump($sub_data);

                $message->to('googleadmin@gmail.com')->subject($sub_data);
                dump('email sent');

            });

        } catch (\Exception $e) {
            dump($e->getMessage());
        }

    }

email.order_mail_customer.blade.php file: email.order_mail_customer.blade.php 文件:

<html>
    <body style="margin: 0; padding: 0;">
        @if(count($order_details) > 0)

        <table cellpadding="0" cellspacing="0" width="600" align="center" style="border:1px solid #ddd;">
                    
            
            <tr>
                <td style="border-top: 5px solid #f7d501;">
                <table style="padding:10px;width:100%;">
                    <tr>
                        <td align="center">
                            @php $path = url('').'/public/images/noimage/default_image_logo.jpg'; @endphp
                            @if(count($logo_settings_details) > 0)
                            @php
                                foreach($logo_settings_details as $logo_set_val){ }
                            @endphp
                            @if($logo_set_val->admin_logo != '')
                                @php $filename = public_path('images/logo/').$logo_set_val->admin_logo; @endphp 
                                @if(file_exists($filename))
                                @php $path = url('').'/public/images/logo/'.$logo_set_val->admin_logo; @endphp
                                @endif
                            @endif                          
                            @endif
                            <img src="{{$path}}" alt="@lang(Session::get('front_lang_file').'.ADMIN_LOGO')" class="img-responsive logo"  width="100">
                        </td>                       
                    </tr>
                </table>
                </td>
            </tr>
            

Exception message: Undefined variable: logo_settings_details in email.order_mail_customer.blade.php异常消息:未定义变量:email.order_mail_customer.blade.php 中的 logo_settings_details

Above code running OK when I set queue driver=sync and without queue.当我设置队列驱动程序=同步且没有队列时,上面的代码运行正常。

But I got undefined property/variable on order_mail_customer.blade.php when I'm using queue by setting up driver=database and implements ShouldQueue to NewOrderListener file.但是当我通过设置 driver=database 并将 ShouldQueue 实现到 NewOrderListener 文件来使用队列时,我在 order_mail_customer.blade.php 上得到了未定义的属性/变量。 Hopefully someone could help me to solve this problem.希望有人可以帮助我解决这个问题。 Thanks in advance.提前致谢。

Nevermind, I've found the issue, this variable couldn't be call because of this variable is static variable, it get destroy before the queue got running.没关系,我发现了问题,这个变量不能被调用,因为这个变量是 static 变量,它在队列运行之前就被破坏了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM