【问题标题】:Events to send mail in Laravel 5.1在 Laravel 5.1 中发送邮件的事件
【发布时间】:2015-07-08 10:29:54
【问题描述】:

我正在尝试在 Laravel 5.1 中实现事件。触发时的事件将发送邮件。

我做了以下步骤:

首先,在 EventServiceProvider 中,我在 $listen 中添加了这个

'send.mail' => [
            \App\Listeners\CreateTicketMail::class,
        ],

其次,创建了一个新的 Event 类——SendActionEmails

然后是 Listener 类中此事件的处理程序 - CreateTicketMail

public function handle(SendActionEmails $event)
{
    dd($event);
}

现在当我触发这个事件send.mail 时,我得到一个错误

Event::fire('check.fire');

Argument 1 passed to App\Listeners\CreateTicketMail::handle() must be an instance of App\Events\SendActionEmails, none given

另外,我在哪里可以将数据发送到邮件将使用的事件。数据喜欢到,从,主题。

我发现在触发事件时,作为参数传递给火的一种方法。

Event::fire('check.fire', array($data));

但是,我如何在监听器中处理这些数据???

【问题讨论】:

    标签: php events laravel laravel-5 laravel-5.1


    【解决方案1】:

    您需要将事件对象传递给触发方法并监听一个类似事件类的事件:

    在 EventServiceProvider 中:

    SendActionEmails::class => [
        \App\Listeners\CreateTicketMail::class,
    ],
    

    事件类:

    class SendActionEmails {
      public $data;
    }
    

    触发事件并传递一些数据:

    $event = new SendActionEmails;
    $event->data = 'some data';
    Event::fire($event);
    

    【讨论】:

      猜你喜欢
      • 2016-01-12
      • 1970-01-01
      • 2018-06-25
      • 1970-01-01
      • 2017-09-25
      • 1970-01-01
      • 2015-11-27
      • 2017-09-22
      • 2018-08-12
      相关资源
      最近更新 更多