Timestamps
Timestamps are a feature of the model used for tracking changes on your entities. With it, you can check when was the model soft deleted, created or last updated.
Timestamps
Properties
createdAt
The createdAt
is a static property on the model. The default value is 'createdAt'
. You may override this if the expected timestamp attribute is named differently. The letter casing is no concern here as getCreatedAtName will update it to the correct casing.
updatedAt
The updatedAt
is a static property on the model. The default value is 'updatedAt'
. You may override this if the expected timestamp attribute is named differently. The letter casing is no concern here as getUpdatedAtName will update it to the correct casing.
timestamps
The timestamps
is a read only attribute that signifies whether the model uses timestamps or not. The default value is true
;
Methods
getCreatedAtName
The getCreatedAtName
method returns the value of the static createdAt value with the letter casing set to the given attributeCasing.
getUpdatedAtName
The getUpdatedAtName
method returns the value of the static updatedAt value with the letter casing set to the given attributeCasing.
usesTimestamps
The usesTimestamps
method returns the value of the timestamps
touchasync
The touch
method sends a PATCH
request with the new updatedAt attribute value. It updates the attribute from the response data.
TIP
Your backend should probably not trust this input, but generate its own timestamp.
freshTimestampsasync
The freshTimestamps
method sends GET
request selecting only the createdAt and updatedAt attributes, which are updated from the response on success.
Soft Deletes
Properties
deletedAt
The deletedAt
is a static property on the model. The default value is 'deletedAt'
. You may override this if the expected timestamp attribute is named differently. The letter casing is no concern here as getDeletedAtName will update it to the correct casing.
softDeletes
The softDeletes
is a read only attribute that signifies whether the model uses soft deleting or not. The default value is true
;
trashed
The trashed
is a getter property that returns a boolean depending on whether the model has the deletedAt set to a truthy value.
Methods
getDeletedAtName
The getDeletedAtName
method returns the value of the static deletedAt value with the letter casing set to the given attributeCasing.
usesSoftDeletes
The usesSoftDeletes
method returns the value of the softDeletes
deleteasync
The delete
method is an extension of the api calling method delete. If the model is not using softDeletes the logic will fall back to the original delete method's logic therefore, method accepts an optional object argument which will be sent along on the request in the body.
This method sends a DELETE
request with the new deletedAt attribute value. It updates the attribute from the response data.
TIP
Your backend should probably not trust this input, but generate its own timestamp.
restoreasync
The restore
methods sends a PATCH
request with the nullified deletedAt attribute value. It updates the attribute to null
on successful request.