【发布时间】:2019-04-13 13:36:27
【问题描述】:
我正在尝试通过我的应用向成员发送电子邮件,但收到以下错误:
production.ERROR:调用未定义的方法 Illuminate\Database\Query\Builder::routeNotificationFor() {"exception":"[object] (BadMethodCallException(code: 0): 调用 未定义的方法 Illuminate\Database\Query\Builder::routeNotificationFor() at /var/www/vhosts/.../laravel/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2483)
我有具有 Notifiable 特征的成员模型,奇怪的问题是在我的本地计算机上发送电子邮件...问题出在生产上...
有什么想法吗?
通知被触发:
Notification::send($members_to_notify, new CommMessage($communication));
CommMessageclass 是:
CommMessage.php
namespace App\Notifications\Communications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use App\Mail\Communications\Message as Mailable;
class CommMessage extends Notification implements ShouldQueue
{
use Queueable;
private $communication;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($communication)
{
$this->communication = $communication;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return Mailable
*/
public function toMail($notifiable)
{
return (new Mailable($this->communication))->to($notifiable->email);
}
}
可邮寄的Message 类是:
Message.php
namespace App\Mail\Communications;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class Message extends Mailable
{
use Queueable, SerializesModels;
/**
* The appointment instance.
*
* @var Appointment
*/
public $communication;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($communication)
{
$this->communication = $communication;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$this->replyTo($this->communication->school->email)
->markdown('emails.communications.message');
$this->subject($this->communication->title);
$this->withSwiftMessage(function ($message) {
$message->getHeaders()
->addTextHeader('X-Mailgun-Variables', json_encode([
'model_id' => $this->communication->id,
'model' => get_class($this->communication),
'email_type' => 11 //Communication message (EmailLogType)
]));
});
}
}
【问题讨论】:
标签: laravel email notifications