在Mail :: send() - Laravel中发送给用户的电子邮件之前是否有任何方法

时间:2017-05-29 10:59:55

标签: laravel laravel-5 laravel-5.2

我在laravel的多个地方实施了var getAllMembers = function (obj) { var members = {}, toTest; members.properties = []; members.methods = []; //construct object if argument is a constructor toTest = (obj.constructor === Function) ? new obj() : obj; for (var prop in toTest) { if (typeof toTest[prop] != 'function') members.properties.push(prop); else members.methods.push(prop); } return members; } function demo_class(na, nb) { this.a = na; this.b = nb; this.funca = function () { console.log(this.a); } this.funcb = function () { console.log(this.b); } } var x = new demo_class(1234, 4321); var members = getAllMembers(x); console.log(members.properties); // [ 'a', 'b' ] console.log(members.methods); // [ 'funca', 'funcb' ] var members = getAllMembers(demo_class); 。我必须在发送邮件之前实现一些代码。所以,我正在寻找在laravel中使用Mail::send()发送电子邮件之前首先调用的任何方法。

这将节省我在发送邮件之前实施新代码的时间。

1 个答案:

答案 0 :(得分:2)

您需要执行两个事件才能使用。在发送邮件之前会触发MessageSending事件,之后会触发MessageSent。这些事件提供了Swift_Message邮件实例,可能会派上用场。创建一个事件监听器并将其附加到事件来处理它们。

Illuminate\Mail\Events\MessageSending
Illuminate\Mail\Events\MessageSent

https://laravel.com/docs/5.2/mail#events

https://laravel.com/docs/5.2/events#defining-listeners