Events vs Observers in laravel

Observers and events do not do the same thing at all.

Simple Difference

Observers are basically predefined events that happen only on Eloquent Models (creating a record, updating a record, deleting, etc). Events are generic, aren't predefined, and can be used anywhere, not just in models.

Observers:

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.

Reference Taken From : https://www.scratchcode.io/laravel/difference-between-events-and-observers-in-laravel/


OK. So, clear up one thing Events and Observers are not doing same things.

What is Event ?

Event is triggered when specific task happens. Such as, some model is created, updated, delete (these are the default ones from laravel). You can dispatch/trigger your custom events as well product.liked or user.commented.

https://laravel.com/docs/5.7/events#defining-events

What are observers ?

As name states these classes observes/handles those events above mentioned. So if we say we want to do something when user is created or user is creating (this is before making an entry to DB). We define observers and if you are familiar with before and after methods methodology you can relate.

https://laravel.com/docs/5.7/eloquent#observers