Download the PHP package eribloo/laravel-model-snapshots without Composer

On this page you can find all versions of the php package eribloo/laravel-model-snapshots. 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-model-snapshots

Laravel package for storing model versions

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

:warning: Disclaimer

This package is still under development and may change often.

Introduction

This package allows creating snapshots of models.

While a typical approach of adding a version column is often enough when there is a need of versioning models, this package stores snapshots in dedicated table. This provides better control over snapshotting process and keeps your tables clean.

My motivation while creating this package was to create configurable snapshots only when I need them, in contrast to generating new version with every update, while keeping connection to up-to-date original model.

Table of contents

Installation

You can install the package via composer:

You can publish and run the migrations with:

You can publish the config file with:

This is the contents of the published config file:

Usage

Basics

Creating snapshots

You can create snapshot by using a helper snapshot() function:

This will snapshot model using default options defined in EriBloo\LaravelModelSnapshots\SnapshotOptions class:

Each snapshot stores an array of model attributes, options that it was created with, version and optional description.

Snapshots provide toModel(bool $fillExcludedAttributes = false) method, that returns model filled with snapshotted attributes. If optional fillExcludedAttributes option is true, returned model will use current model attributes as a base, otherwise missing attributes will be null.

Accordingly, if you retrieve collection of snapshots you can use its toModels(bool $fillExcludedAttributes = false) method to map all snapshots to corresponding classes.

Reverting, branching and forking snapshots

Snapshots have 3 helper methods to revert model, or to create a new one, from its snapshot:

Attributes excluded from snapshotting will be filled with current model values.

Relations

In addition, package provides separate table to store snapshot relations with other models. There are morphToMany and morphToOne relations available that return either Snapshots or Models in HasSnapshotRelations trait.

Configuring

Snapshot options

Options can be defined by creating getSnapshotOptions() method on model:

Configurable options include:

Most can be later overridden while snapshotting using those methods:

Versionist

Versionist is a class responsible for determining next snapshot version. There are 2 classes available by default:

If you would like to create your own versionist class it must implement EriBloo\LaravelModelSnapshots\Contracts\Versionist with methods:

Traits

While no trait is needed to make a snapshot, package provides 2 helper traits for retrieving snapshots:

Events

There are a few events that get dispatched:

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

//: # ()

//: # ()

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-model-snapshots with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
fidum/laravel-eloquent-morph-to-one Version ^2.2
illuminate/contracts Version ^9.0|^10.0|^11.0
spatie/laravel-package-tools Version ^1.14.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 eribloo/laravel-model-snapshots contains the following files

Loading the files please wait ....