且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除模型后如何触发Laravel(5.6)事件?

更新时间:2023-12-03 13:19:16

需要从处理已删除模型的事件中删除SerializesModels特性.

The SerializesModels trait needs to be removed from events that deal with deleted models.

SerializesModels是一个特征,它仅在序列化事件(或作业)时存储模型的ID,而在未序列化事件时从数据库中重新获取模型.

SerializesModels is a trait that only stores the id of the model when the event (or job) is serialized, and refetches the model from the database when the event is unserialized.

这允许排队的进程在运行时从数据库中获取新模型,因此它们不会使用过时的信息运行,但是当您从数据库中删除该行时,这将是不可靠的.

This allows queued processes to get a fresh model from the database when they run so they are not running with outdated information, but this would not be reliable when you're deleting that row from the database.