eloquent-immutable
eloquent-immutable copied to clipboard
Enforce table immutability using Laravel Eloquent
Enforce table immutability using Laravel Eloquent
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 [email protected] instead of using the issue tracker.
Credits
- Miguel Piedrafita
- All Contributors
License
The MIT License (MIT). Please see License File for more information.