May*_*iya 12
观察者和事件根本不做相同的事情。
简单差异
观察者基本上是预定义的事件,仅在雄辩模型上发生(创建记录,更新记录,删除等)。事件是通用的,不是预定义的,可以在任何地方使用,而不仅限于模型中。
观察员:
An observer watches for specific things that happen within eloquent such as saving, saved, deleting, deleted (there are more but you should get the point). Observers are specifically bound to a model.
Events:
Events are actions that are driven by whatever the programmer wants. If you want to fire an event when somebody loads a page, you can do that. Unlike observers events can also be queue, and ran via laravel's cron heartbeat. Events are programmer defined effectively. They give you the ability to handle actions that you would not want a user to wait for (example being the purchase of a pod cast)
The documentation does a very good job covering these.
| 归档时间: |
|
| 查看次数: |
1293 次 |
| 最近记录: |