Download the PHP package gazugafan/laravel-temporal without Composer

On this page you can find all versions of the php package gazugafan/laravel-temporal. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-temporal

Laravel Temporal Models

Temporal models and versioning for Laravel

You know what's crazy? Database updates. You update a record and BAM! The previous version of the record is overwritten. What was it like before you updated it? No one knows. The data has been lost forever. More like database overwrites, amirite?

If you're not in the business of losing data forever, you should give temporal models a try! It's like version control for your database records. Now when you update something, the previous version of it is kept intact, and a new revision is inserted instead.

Normally you're only going to care about the current versions of things, so by default that's all you'll get when querying. But the old versions are always there too if you want to get at them. Now when someone asks "what was this thing like before the latest change?" or "what did this thing dress as last Halloween?" or "did this thing always have a tail?", you'll have all the answers.

Requirements

Installation

Install via Composer...

For Laravel 5 use the version 1.1

For Laravel 6.0 use the version 2.0

For Laravel 7.0 use the version 3.0

For Laravel 8.0 use the version 4.0

For Laravel 9.0 use the version 5.0.1

Overview

Temporal models get three new fields...

Whenever you save or update a model, the previous version's is updated to mark the end of its lifespan, and a new version is inserted with an incremented .

When querying for temporal models, we automatically constrain the query so that only current versions are returned. Getting at old revisions is also possible using added methods.

When paired with laravel-changelog, this will give you the history of every change made to a record, including who made each change and exactly what was changed.

Schema Migration

You'll need to modify your table's schema a bit. The bad news is that Laravel doesn't really "support" the modifications we need to make, so we have to resort to some ugly workarounds. The good news is that I made a helper class that handles all the dirty work for you!

What's actually going on here...

The actual changes necessary are:

  • Add an unsigned integer column as an additional primary key.
  • Add datetime and columns.
  • Add indexes to make sure queries stay just as fast. I'd recommend two additional indexes...
    • for getting current revisions (which we do all the time)
    • for getting revisions at a certain date/time

Laravel doesn't have an easy mechanism for specifying multiple primary keys along with an auto-increment key. To work around this, does some raw MySQL commands. This most likely will NOT work on non-MySQL databases like SQLite.

Model Setup

To make your model temporal, just add the trait to the model's class...

You can also customize the column names and maximum temporal timestamp, if you'd like to change them from the defaults...

Usage

Saving temporal models

When you first save a new record, it is inserted into the database with a of 1, a of the current date/time, and a of WAY in the future ('2999-01-01' by default). Thus, this first revision is currently active from now to forever.

The next time you save this record, the previous revision's is automatically updated to the current date/time--marking the end of that version's lifespan. The new revision is then inserted into the database with its incremented by 1, and its and updated as before. Thus, the previous version is now inactive, and the new version is currently active.

You can only save the newest version of a record. If you find an old version of something and try to modify it, an error will be thrown... you can't change the past.

If you want to overwrite the latest revision, use instead of . This will simply update the revision instead of inserting a new one. It totally defeats the purpose of using temporal models, but it can be useful for making frequent tiny changes. Like incrementing/decrementing something on a set schedule, or updating a cached calculation.

You can also automatically overwrite whenever you perform a if only columns you've defined as have been changed. Just add an array property to your model like this: and we'll automatically perform an overwrite (instead of inserting a new version) when only those columns are changing. If you notice lots of unnecessary versions in your table just because of one or two columns changing that you don't care about the history of, add those columns here!

Retrieving temporal models

By default, all temporal model queries will be constrained so that only current versions are returned.

If you want to get all versions for some reason, you can use the method to remove the global scope...

You can also get specific versions, and traverse through versions of a certain record...

And there are similar query builder methods...

Deleting temporal models

When you call on a temporal model, we don't actually DELETE anything. We just set its to now--thereby marking the end of that revision's lifespan. And, without a current revision inserted to follow it, the record is effectively non-existant in the present. So, querying for it like normal won't get you anything.

It's like you get SoftDelete functionality for free! You can even restore deleted records...

Keep in mind that you can only delete/restore the current/latest version of a record. If you really want to permanently remove a record from the database, you can use . This DELETEs every version of the record, and cannot be undone.

Reference

Check out the full documentation here

Pitfalls

Credits

Inspired by navjobs/temporal-models and FuelPHP's temporal models


All versions of laravel-temporal with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0.2
illuminate/database Version ^9.0
illuminate/events Version ^9.0
doctrine/dbal Version ^2.5
laravel/helpers Version ^1.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package gazugafan/laravel-temporal contains the following files

Loading the files please wait ....