这是我第一次在Laravel / Lumen中使用活动 .
我实际上正在使用流明,当新用户注册以便在后台发送电子邮件时,我正在尝试调度Mailable的实例 .
我相信我已经把它设置正确,但我一直收到这个错误......
类型错误:传递给Illuminate \ Mail \ Mailable :: queue()的参数1必须实现接口Illuminate \ Contracts \ Queue \ Factory,给出Illuminate \ Queue \ DatabaseQueue的实例
我实际上无法在错误消息中看到问题来自哪里,例如没有行号 .
但是,这是我的代码......
AuthenticationContoller.php
$this->dispatch(new NewUser($user));
NewUser.php
<?php
namespace App\Mail;
use App\Models\User;
use Illuminate\Mail\Mailable;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class NewUser extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
protected $user;
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('test')->to('test@test.com', 'Test')
->from('test@test.com', 'test')->replyTo('test@test.com', 'test')
->subject('Welcome to the blog!');
}
}
1 回答
我遇到了同样的问题 . 似乎Lumen和Illuminate / Mailer不能很好地协同工作 .
但是我在a Github thread找到了相当简单的修复方法 .
基本上,您只需在app / Providers目录中创建一个新的服务提供者 .
MailServiceprovider.php
然后,您只需通过添加以下行在
bootstrap/app.php
中注册此服务提供程序而不是默认服务提供程序:$app->register(\App\Providers\MailServiceProvider::class);