我正在尝试将包含具有模型()的属性的可邮寄邮件排队,该模型(Order
)具有二进制 id。
<?php
namespace App\Mail;
use App\Order;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class OrderShipped extends Mailable
{
use Queueable, SerializesModels;
/**
* The order instance.
*
* @var Order
*/
public $order;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(Order $order)
{
$this->order = $order;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('emails.orders.shipped');
}
}
Order
实现Serializable
接口。在serialize
模型的方法中,我将二进制 id 转换为字符串,因此可以将其正确编码为 json。
不幸的serialize
是,当我想对邮件进行排队时,该方法永远不会被调用。
这是框架中的错误还是我遗漏了什么?
我还在 PHP 文档中注意到,当使用Serializable
接口时,不再支持__sleep
and方法:__wakeup
实现此接口的类不再支持 __sleep() 和 __wakeup()。
但这种Illuminate\Queue\SerializesModels
特性似乎超越了它们......
编辑
我将这个特征用于我的二进制 ids。在我的serialize
方法中,我只是调用$this->toArray()
.