Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我认为标题说明了一切.. 在 Laravel 应用程序中,我在代码中多次分派一个事件(或多个事件)并为它们有一个订阅者,但我希望它只处理一次,无论多少次在流中触发事件。
有什么明确的方法可以做到这一点,或者我需要一个 ..singleton 类或类似的东西?
谢谢
您可以Event::forget('YourEvent');在第一次调度后在订阅者中取消监听事件。
Event::forget('YourEvent');
缺点是该事件的所有其他侦听器也将被删除。