martinbean / eloquent-encryptable
Adds encryptable attributes to Eloquent models, for storing sensitive data.
Requires
- illuminate/database: ^6.20.12|^7.0
- illuminate/encryption: ^6.0|^7.0
- illuminate/support: ^6.0|^7.0
Requires (Dev)
- orchestra/testbench: ^5.0
This package is auto-updated.
Last update: 2021-02-20 12:11:52 UTC
README
Adds encryptable attributes to Eloquent models, for storing sensitive data, in Laravel 6.x and 7.x applications.
NOTE: If you are using Laravel 8.x, you DO NOT NEED this package. Laravel offers a native encrypted
cast that works on strings, collections, and objects. For more information, see laravel.com/docs/8.x/eloquent-mutators#attribute-casting
Usage
Simply add the trait to your Eloquent model, and define an array of attributes
whose values should be encrypted in your database in an $encryptable
property:
<?php namespace App; use Illuminate\Database\Eloquent\Model; use MartinBean\Eloquent\Encryptable; class Patient extends Model { use Encryptable; protected $encryptable = [ 'medical_conditions', 'medical_notes', 'allergies_and_reactions', 'medications', 'blood_type', 'is_organ_donor', 'emergency_contact_id', ]; }
You can retrieve these attributes as normal and they’ll be decrypted:
$medical_conditions = $patient->medical_conditions;
License
Licensed under the MIT License.
Support
Please create an Issue for any problems with this library.