在我的 forge 生产服务器上,我配置了 Laravel 5.3 通知,所有的通知都使用了Illuminate\Bus\Queueabletrait 并实现了Illuminate\Contracts\Queue\ShouldQueue接口。这是在App\Notifications\BaseNotification我创建的一个类中完成的,我的所有通知类都扩展了。
我还有一个配置为运行队列的工作人员。
一切都很好,但是今晚我在执行通知时开始收到此错误:
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
Run Code Online (Sandbox Code Playgroud)
报告错误的类的代码如下:
<?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'),
];
}
}
Run Code Online (Sandbox Code Playgroud)
OBS:该via方法是在定义BaseNotification类和translation方法仅仅是一个辅助摆脱郎文件的消息。
我不确定这是否是框架问题,也许当 Laravel 尝试对我的工作进行反序列化时有问题。但我不知道如何才能发现或如何处理。
当我在本地机器(也使用队列)上执行相同的工作流程时,工作正常。
你们能帮我吗?
这部分来自给定的错误消息,
...Please ensure that the class definition
"CenaZero\Notifications\Orders\OrderCompletedOwnerNotification"
of the object you are trying to operate on was loaded...
Run Code Online (Sandbox Code Playgroud)
显示该类未自动加载。
将包含命名空间下使用的类的基文件夹添加到Composer 中的映射命名空间CenaZero数组中。这样,在脚本尝试使用命名空间下的类反序列化对象之前,会自动加载它们。
作曲家.json
{
"autoload": {
"psr-4": {
"CenaZero\\": "<relative-path-to-root-folder-of-namespace>/",
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
768 次 |
| 最近记录: |