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 important event. It can also be defined as a thing that occurs in a specific period of time.
I like these two definitions, because they are very consistent with our content. In fact, in a sense, you can regard this specific period as the model's lifecycle.
You can create a new instance, update an existing instance, or delete it. Each operation you can perform involves two events.
I just created a record, deleted the record, and I am updating the record. It sounds natural, right?
During the model lifecycle, when something happens, Eloquent triggers some events:
Creating
Created
Updating
Updated
Saving
Saved
Deleting
Deleted
Restoring
Restored
Each operation corresponds to two independent events. As you may imagine, they refer to separate moments. We have created an operation as an instance:
You have a creating event, which can be understood as "the creation operation is about to happen", and "created" indicates "the event has occurred ".
Scientists may say:
Creating: indicates the t-1 moment.
Created: it is related to the t + 1 moment
Therefore, the following three basic operations have two corresponding events: create, update, and delete ).
In addition, you can see two other operations: save and restore ). But don't worry. They are not complicated:
Save: you only need to know that the save operation is related to create and update. Let's assume that you need to add a behavior, whether the application creates a new record or updates an existing record. Do I have to declare the same thing twice? You only need a common save operation.
Restroe: the restore operation is used when a model uses soft delete and the undo operation is performed.
Well, I know what you are thinking: What is the deeper meaning of this concept? We use instances to answer this question.