What is an event? If you search for this word in Google, you will get multiple results. For example, it is defined as something that has occurred or is considered to have occurred; an accident, especially a particularly significant one. It can also be defined as something that happens at a specific point in a given period of time.
I like these two definitions because they fit well with our content. In fact, in a sense, you can think of this particular period as the life cycle of the model.
You can create a new instance, update an existing instance, or delete it. Each operation you can do involves two events.
On the basis of this: I just created a record, I deleted the record, I'm updating that record, it sounds natural, right?
In the life cycle of a model, when something happens, eloquent triggers some events:
- Creating
- Created
- Updating
- Updated
- Saving
- Saved
- deleting
- Deleted
- Restoring
- Restored
For each operation, it corresponds to two separate events. As you might imagine, they refer to a single moment. We have created the operation as an instance:
You have a creating event that can be understood as "the creation operation is about to occur" and created means "the event has already occurred."
Scientists may say:
- Creating: Is the t–1 moment
- Created: is associated with the T + 1 moment
So, for the following three basic operations, there are two corresponding events: Create, update, and delete.
In addition, you can see two other actions: Save and Recovery (restore). But, don't worry, they're not complicated:
- Save: You just need to know that the save operation is related to create and update. Let's say you need to add a behavior where the application creates a new record or updates an existing one. Does it have to be declared two times for the same thing? Only one normal save operation is required.
- Restroe: The restore operation is used when one of your models uses a soft delete and performs a undo operation.
Well, I know what you're thinking: What's the meaning of the deeper layer of the concept? We use examples to answer.