protected string $temporal_max = '2999-01-01 00:00:00'
The datetime to use for the end of the currently active version
protected string $version_column = 'version'
The integer column used to represent the version number of a revision
protected string $temporal_start_column = 'temporal_start'
The datetime column used to represent the beginning of a version
protected string $temporal_end_column = 'temporal_end'
The datetime column used to represent the end of a version
Soft Deletes the record by updating the temporal_end to the current datetime--making it invalid in the present
boolean save(array $options)
Save the model to the database.
If the record already exists, instead of updating it, we will update the temporal_end column and insert a new revision. New revisions automatically have their temporal_start set to the current time, and temporal_end set to the max timestamp.
boolean overwrite()
Updates the record without inserting a new revision--overwriting the current revision.
Fires overwriting and overwritten events. Does not fire update or save events.
boolean restore()
Restores the deleted revision. If this revision wasn't deleted (there is presently an active revision), nothing happens.
Fires restoring and restored events. Does not fire update or save events.
boolean purge()
Permanently removes all versions of this record from the database--destroying all of the data. THIS CANNOT BE UNDONE! Fires purging and purged events. Does not fire update, save, or delete events.
previousVersion()
Returns the previous version of the record, or null if there is no previous version.
nextVersion()
Returns the next version of the record, or null if there is no next version.
firstVersion()
Returns the first version of the record, or null if there is no first version.
atVersion($version)
Returns the specified version of the record, or null if the specified version does not exist.
- $version int The version number to retrieve
currentVersion()
Returns the current version of the record, or null if the record has been deleted.
latestVersion()
Returns the latest version of the record, or null if there is no latest version. Note that this may NOT be the currently active version, if the record was deleted.
atDate(Carbon|string $datetime)
Returns the record as it existed on the specified date, or null if the record did not exist then.
If multiple versions of the record happen to exist at the same second, only the newest one will be returned.
- $datetime Carbon|string - The date/time you want to search for a revision at. Can be a Carbon instance, or a datetime string that your database recognizes.
inRange(Carbon|string $from = null, Carbon|string $to = null)
Returns an array of any versions of the record that existed at some point during the specified date range, or an empty array if the record did not exist at all during the date range.
The array is sorted from oldest to newest.
- $from Carbon|string - If specified, only versions that existed on or after this date/time will be returned
- $to Carbon|string - If specified, only versions that existed before this date/time will be returned
\Illuminate\Database\Eloquent\Builder currentVersions()
Starts a query constrained to only the current versions. This is accomplished in normal queries automatically, as the global temporal scope applies the same constraint. Feel free to use this method instead if you want, though.
- This method is static.
currentVersions()
The currentVersions builder method will constrain the query to revisions that are currently active. This is normally applied automatically as a global scope, so this method is not usually necessary.
allVersions()
The allVersions builder method will remove the constraint that normally causes just the currently active versions to be returned.
firstVersions()
The firstVersions builder method will constrain the query to original revisions.
versionsAt($version = 1)
The versionsAt builder method will constrain the query to revisions with the specified version number.
- $version int The version number to retrieve
versionsAtDate($datetime = null)
The versionsAtDate builder method will constrain the query to revisions that were active during the specified date.
- $datetime Carbon|string - The date/time you want to search for revisions at. Can be a Carbon instance, or a datetime string that your database recognizes.
versionsInRange(Carbon|string $from = null, Carbon|string $to = null)
The versionsInRange builder method will constrain the query to revisions that were active at some point in the specified date range.
You can specify null as the $from or $to date to get all revisions in that direction of time.
- $from Carbon|string - If specified, only versions that existed on or after this date/time will be returned
- $to Carbon|string - If specified, only versions that existed before this date/time will be returned