m1guelpf/eloquent-immutable

Enforce table immutability using Laravel Eloquent

dev-master 2018-10-31 10:56 UTC

This package is auto-updated.

Last update: 2024-10-17 05:24:44 UTC


README

Latest Version on Packagist Total Downloads

Installation

You can install the package via composer:

composer require m1guelpf/eloquent-immutable

Usage

To make a model immutable, you'll first need to add the immutable trait to it:

use Illuminate\Database\Eloquent\Model;
use M1guelpf\EloquentImmutable\Immutable;

class YourModel extends Model {
    use Immutable;

    //
}

You can optionally enable an extra layer of security by storing a hash of the model's properties in your database. To do this, add a field to your migration, then toggle the fature in the model:

// database/migrations/2014_10_12_000000_create_your_table.php
Schema::create('your_table', function (Blueprint $table) {
    $table->string('hash');

    //
});

// app/YourModel.php
class YourModel extends Model {
    $immutableCheck = true;

    //
}

We'll automatically check the hash matches when the model is retrieved.

Limitations

Due to Laravel limitations, we cannot hook into mass updates or mass deletes.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email soy@miguelpiedrafita.com instead of using the issue tracker.

Credits

License

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