在我的forge生产服务器上,我配置了Laravel 5.3通知,所有通知都使用Illuminate\Bus\Queueable
特征并实现Illuminate\Contracts\Queue\ShouldQueue
接口。这是在我创建的App\Notifications\BaseNotification
类中完成的,我的所有通知类都扩展了。
我还有一个配置为运行队列的worker。
一切都好了,但今晚我在执行通知时开始收到此错误:
Symfony\Component\Debug\Exception\FatalErrorException: Illuminate\Notifications\ChannelManager::sendNow(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "CenaZero\Notifications\Orders\OrderCompletedOwnerNotification" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition
in /home/forge/cenazero.com.br/vendor/laravel/framework/src/Illuminate/Notifications/ChannelManager.php:64
报告错误的类中的代码如下:
<?php
namespace CenaZero\Notifications\Orders;
use CenaZero\Models\Order;
use CenaZero\Notifications\BaseNotification;
use Illuminate\Notifications\Messages\MailMessage;
use NotificationChannels\Gcm\GcmMessage;
use NotificationChannels\Zenvia\ZenviaMessage;
class OrderCompletedProducerNotification extends BaseNotification
{
private $order;
public function __construct(Order $order)
{
$this->order = $order;
}
public function toMail($notifiable)
{
$data = [
'order' => $this->order,
'item' => $this->order->item,
'product' => $this->order->item->product,
'producer' => $notifiable,
'to' => $notifiable->email,
];
return (new MailMessage)
->view(['emails.orders.completed.producer', 'emails.orders.completed.producer-plain'], $data)
->subject($this->translation('subject'));
}
public function toZenvia($notifiable)
{
return ZenviaMessage::create()
->content($this->translation('message'))
->id('order-completed-producer-' . $this->order->id);
}
public function toGcm($notifiable)
{
return GcmMessage::create()
->title($this->translation('title'))
->message($this->translation('message'));
}
public function toArray($notifiable)
{
return [
'id' => $this->order->id,
'status_id' => $this->order->status_id,
'message' => $this->translation('title'),
'description' => $this->translation('message'),
];
}
}
Obs: via
类中定义了BaseNotification
方法,而translation
方法只是从lang文件中获取消息的帮助器。
我不确定这是否是一个框架问题,当Laravel尝试反序列化我的工作时可能会出现问题。但我不知道我怎么能发现它或如何处理它。
当我在本地计算机上执行相同的工作流程(也使用队列)时,工作正常。
你们能以某种方式帮助我吗?
答案 0 :(得分:0)
此部分来自给定的错误消息,
...Please ensure that the class definition
"CenaZero\Notifications\Orders\OrderCompletedOwnerNotification"
of the object you are trying to operate on was loaded...
表明该类没有自动加载。
将包含CenaZero
命名空间下使用的类的基本文件夹添加到mapped namespaces in composer的数组中。这样,在脚本尝试使用它们反序列化对象之前,将自动加载名称空间下的类。
composer.json
{
"autoload": {
"psr-4": {
"CenaZero\\": "<relative-path-to-root-folder-of-namespace>/",
}
}
}