【发布时间】:2018-12-11 09:00:20
【问题描述】:
我的 Laravel 应用程序中有一个事件,对于特定记录,它超出了 Pusher 允许的最大限制(10240 字节)。 Laravel 序列化 Event 类上的每个公共属性是否正确?如果是这样,我怀疑序列化模型不应超过 10kb 限制,但无论如何它都会失败。有什么方法可以减小数据内容的大小?
class PostChanged implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $post;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Post $post)
{
$this->post = $post;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('post-channel.'.$this->post->id);
}
public function broadcastWith()
{
$extra = [
'data' => $this->post->data,
];
return array_merge($this->post->toArray(), $extra);
}
}
产生:
The data content of this event exceeds the allowed maximum (10240 bytes).
See http://pusher.com/docs/server_api_guide/server_publishing_events for more info
【问题讨论】:
-
$post的内容是什么?另外,你为什么要添加$post->data两次?它已经包含在$post变量中。 -
我发布的代码只是我的代码示例,用于展示我的实现。这不是实际的代码。我的问题是关于
$post对象的序列化与否。
标签: laravel events serialization limit pusher