问题描述
当我尝试使用Postman或Insomnia进行POST来存储带有数据的电子邮件时,我不明白为什么。
我有以下字段:
public function up()
{
Schema::create('polls',function (Blueprint $table) {
$table->id();
$table->text('Now');
$table->json('paramJson');
$table->enum('status',['a','b','c','d'])->default('a');
});
}
投票模型:
protected $fillable = ['Now'];
protected $casts = ['paramJson' => 'array'];
PollsController.PHP
public function store(Request $request)
{
$poll = request->all();
if($poll['status']=='b')
{
Mail::to('[email protected]')->send(new NotifyPoll($poll));
}
return response()->json(Poll::create($poll),201);
}
Mail / NotifyPoll
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class NotifyPoll extends Mailable
{
use Queueable,SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($data)
{
$this->itemPoll = $data;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from('.......@inBox.mailtrap.io')->subject('Error Poll')->view('mail.notifyErrorPoll',['mail_data'=>$this->itemPoll]);
}
}
失眠的一面,我没有收到任何错误消息,但不幸的是,邮件没有到达。
解决方法
我认为您错过了protected $itemPoll
类中的NotifyPoll
。另外,检查您的日志文件以获取错误堆栈。调试时有很大帮助。