Download the PHP package philiprehberger/laravel-model-diff without Composer

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

Laravel Model Diff

Tests Latest Version on Packagist Last updated

Track and display structured differences between Eloquent model versions with human-readable labels.

Requirements

Installation

Install via Composer:

The service provider and facade are registered automatically via Laravel package auto-discovery.

Publishing the config

This creates config/model-diff.php in your application.

Configuration

Usage

Comparing two model instances

Pass two instances of the same model — a "before" snapshot and an "after" snapshot — to ModelDiff::compare():

Comparing an unsaved dirty model

Use ModelDiff::fromDirty() to inspect changes on a model that has not yet been saved:

Excluding extra attributes at call-site

Filtering results

Use only() and except() to narrow a DiffResult after comparison:

Accessing individual values

Retrieve the old or new value of a single attribute without iterating:

Human-Readable Labels

Using the HasDiffLabels trait

Add the HasDiffLabels trait to any model and define a $diffLabels map:

Attributes without an explicit entry are automatically humanized: billing_address becomes Billing Address.

Retrieving a label directly

API

DiffResult

Method Return type Description
hasChanges() bool true when at least one attribute changed
changedAttributes() string[] Names of changed attributes
getChanges() AttributeChange[] All change objects
only(string[] $attributes) DiffResult New result with only the specified attributes
except(string[] $attributes) DiffResult New result excluding the specified attributes
getBefore(string $attribute) mixed Old value for an attribute (null if not in diff)
getAfter(string $attribute) mixed New value for an attribute (null if not in diff)
toArray() array Plain array — one entry per change
toHumanReadable() array Keyed by label; values formatted for display

toArray() output

toHumanReadable() output

AttributeChange

Property Type Description
$attribute string Raw attribute name
$old mixed Normalized old value
$new mixed Normalized new value
$label string Human-readable label

Cast-Aware Comparison

The package normalizes values before comparing them, so you never get false positives from type mismatches:

Cast type Normalization
date, datetime, immutable_date/datetime Parsed to Carbon and formatted with date_format config
timestamp Parsed to Carbon and formatted with date_format config
array, json, object, collection Decoded and compared by content, not by serialized string
boolean, bool Strict (bool) cast before comparison
integer, int Strict (int) cast
float, double, real Strict (float) cast
decimal:N Strict (float) cast
Backed enum (SomeEnum::class) Compared by ->value; stored as scalar in AttributeChange
Unit enum (SomeEnum::class without backing) Compared by ->name; stored as string in AttributeChange

Note: Associative arrays are compared order-insensitively — ['a' => 1, 'b' => 2] equals ['b' => 2, 'a' => 1]. Sequential (list) arrays are compared in order.

Using the Facade

The ModelDiff facade is registered automatically:

Using the Class Directly

If you prefer not to use the facade, resolve the class from the container or instantiate it directly:

Development

Support

If you find this project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT


All versions of laravel-model-diff with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/database Version ^11.0|^12.0
illuminate/support Version ^11.0|^12.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 philiprehberger/laravel-model-diff contains the following files

Loading the files please wait ...