gpt4 book ai didi

php - 反序列化时 Laravel 通知失败

转载 作者:行者123 更新时间:2023-12-03 17:39:19 42 4
gpt4 key购买 nike

在我的 forge 生产服务器上,我配置了 Laravel 5.3 通知,所有通知都使用 Illuminate\Bus\Queueable trait 并实现了 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

报告错误的类的代码如下:
<?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'),
];
}
}

观察: via方法在 BaseNotification 中定义类,以及 translation方法只是从 lang 文件中获取消息的助手。

我不确定这是否是框架问题,也许当 Laravel 尝试对我的工作进行反序列化时有问题。但我不知道如何才能发现或如何处理。

当我在本地机器(也使用队列)上执行相同的工作流程时,工作正常。

你们能帮我吗?

最佳答案

这部分来自给定的错误消息,

...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 的数组.这样,在脚本尝试使用它们反序列化对象之前, namespace 下的类会自动加载。

composer.json
{
"autoload": {
"psr-4": {
"CenaZero\\": "<relative-path-to-root-folder-of-namespace>/",
}
}
}

关于php - 反序列化时 Laravel 通知失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40074580/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com