m1guelpf / eloquent-immutable
Enforce table immutability using Laravel Eloquent
Fund package maintenance!
m1guelpf
Requires
- php: ^7.1
- illuminate/database: ^5.6
Requires (Dev)
- larapack/dd: ^1.0
This package is auto-updated.
Last update: 2024-11-17 05:31:42 UTC
README
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.