Download the PHP package michaeljmeadows/has-histories without Composer

On this page you can find all versions of the php package michaeljmeadows/has-histories. 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 has-histories

michaeljmeadows/has-histories

A simple trait to aid Eloquent model version history logging.

Installation

You can install the package via composer:

Usage

Add a migration to store your model histories. This should contain all the same fields as your main model table as well as a reference ID to the original model. Your model's history table can be named however your like, but the default convention would be models -> model_histories. We recommend modifying your migrations as shown in this modification of the Laravel Jetstream User migration:

Once the migration has been added, you can simply include the trait in your model's definition:

Restoring Models

Models can be restored using one of three methods:

These functions return true on success and false if a historic state was not found.

restorePrevious() will restore a model to its previous state in the histories table.

restorePreviousIteration(int $index) will restore a model to a state using zero-based numbering. (i.e. restorePreviousIteration(0) is the same as restorePrevious()).

restoreBeforeDate(DateTimeInterface|string $date) will restore a model to the most recent state before the given $date value using the updated_at and created_at fields.

Restoration Notes

Customising Behaviour

Ignored Fields

Not every change to a model's attributes is worth logging. In the Jetstream User example above, it may be that you'd rather ignore changes to email_verified_at. In this case, you can add a protected array attribute $ignoredFields to your model specifying which attributes you're not interested in:

If you choose to ignore fields these should not be included in the history table migration.

Histories Table Name

By default, HasHistories uses the naming convention models -> model_histories when determining the history table name, but if for whatever reason that doesn't work for you, you can specify a different history table name by adding a protected string attribute $historiesTable to your model:

Histories Table Model Reference

By default, HasHistories associates an entry in the history table with a model with an attribute in the form models -> model_id, but if for whatever reason that doesn't work for you, you can specify a different field by adding a protected string attribute $historiesModelIdReference:

Histories Table Connection

By default, HasHistories expects that the history table will use the same connection as the model to which it is applied. Occasionally you may want to specify a different connection for your history table. This can be done with an optional parameter in your saveHistory method call:

When restoring models, the same connection parameter can be added at the end of each method call:


All versions of has-histories with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/database Version ^8.0|^9.0|^10.0
illuminate/support Version ^8.0|^9.0|^10.0
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 michaeljmeadows/has-histories contains the following files

Loading the files please wait ....