PHPackages                             mangopixel/laravel-adjuster - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. mangopixel/laravel-adjuster

ActiveLibrary[Database &amp; ORM](/categories/database)

mangopixel/laravel-adjuster
===========================

A Laravel package for updating your Eloquent models indirectly using an adjustments table.

v1.0.3(9y ago)3429MITPHPPHP ^7.0

Since Jun 12Pushed 9y ago2 watchersCompare

[ Source](https://github.com/mangopixel/laravel-adjuster)[ Packagist](https://packagist.org/packages/mangopixel/laravel-adjuster)[ Docs](https://github.com/mangopixel/laravel-adjuster)[ RSS](/packages/mangopixel-laravel-adjuster/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (7)Versions (5)Used By (0)

Laravel Adjuster
================

[](#laravel-adjuster)

[![Latest Stable Version](https://camo.githubusercontent.com/151780eb3f998215a8fd85b00c7c927393644bf5ef7efad85f549b26cd5ee592/68747470733a2f2f706f7365722e707567782e6f72672f6d616e676f706978656c2f6c61726176656c2d61646a75737465722f762f737461626c653f666f726d61743d666c61742d737175617265)](https://github.com/mangopixel/laravel-adjuster)[![Packagist Downloads](https://camo.githubusercontent.com/3dfac8759b02abb59c5fa014e323f0d41011a06ca7ab47a0e98471c0b1eb7486/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d616e676f706978656c2f6c61726176656c2d61646a75737465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mangopixel/laravel-adjuster)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](license.md)[![Build Status](https://camo.githubusercontent.com/1b60044590e05b036af0b149f0929e1dcc0970e901dd3d64d84cbfdfcdc320ad/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d616e676f706978656c2f6c61726176656c2d61646a75737465722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/mangopixel/laravel-adjuster)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/1c92fbaa0bff8a6c2cc9d2c76031fbe707e2e93b4b72d37f8a4cde4421cd4846/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6d616e676f706978656c2f6c61726176656c2d61646a75737465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/mangopixel/laravel-adjuster/?branch=master)

A Laravel package for updating your Eloquent models indirectly using an adjustments table. This allows you to overwrite a model's attributes without changing the model directly. This can be useful in cases where you don't have control over the data flow of your models.

A concrete example of its usefulness is when you feed a table with data from an API, and use a cron job to keep the table updated with the most recent data. In this case you might want to keep the table untouched so your changes are not overwritten by newer updates without you realising. Updating the table using an adjuster solves this problem as all adjustments you make to the data are stored in another table.

Most of the functionality lives in a trait, making it easy to use in your models. You can also adjust multiple models using the same adjustments table, as it uses polymorphic relationships. The package is well tested and extremely lightweight.

Requirements
------------

[](#requirements)

This package requires:

- PHP 7.0+
- Laravel 5.0+

The default adjustments migration also uses a JSON column to store changes. JSON columns are only supported in MySQL version 5.7 or higher and other databased that support Json. You may also change the migration data type to something else (like text) if your selected database doesn't support JSON columns.

Installation
------------

[](#installation)

Install the package through Composer:

```
composer require mangopixel/laravel-adjuster
```

After updating Composer, append the following service provider to the `providers` key in `config/app.php`:

```
Mangopixel\Adjuster\AdjusterServiceProvider::class
```

You may also publish the package configuration file and migrations using the following Artisan command:

```
php artisan vendor:publish --provider="Mangopixel\Adjuster\AdjusterServiceProvider"
```

The configuration file is well documented and you may edit it to suit your needs. You may also edit the migration file to your liking. However, make sure you update the `adjustable_column` and `changes_column` values in the configuration if you change the default column names.

Usage
-----

[](#usage)

After installing and adding the service provider, you should migrate the `adjustments` table. If you have published the vendor files as described in the installation guide above you should have the new migration file in the migrations folder. In that case you can just run `php artisan migrate`.

### Adding the trait and contract

[](#adding-the-trait-and-contract)

You need to use the `Mangopixel\Adjuster\CanBeAdjusted` trait for every model you want to be able to adjust together with the `Mangopixel\Adjuster\Adjustable` interface which the trait fulfills. An example model:

```
