imhayatunnabi / laravel-hashes
A Laravel package for automatic encryption and decryption of model attributes
Package info
github.com/imhayatunnabi/laravel-model-encryption-decryption
pkg:composer/imhayatunnabi/laravel-hashes
dev-master
2025-04-14 11:28 UTC
Requires
- php: ^7.2|^8.0
- illuminate/database: ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0
- illuminate/encryption: ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0
- illuminate/support: ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^3.0|^4.0|^5.0|^6.0|^7.0|^8.0
- phpunit/phpunit: ^8.0|^9.0|^10.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-10-27 17:35:47 UTC
README
A Laravel package for automatic encryption and decryption of model attributes.
Installation
You can install the package via composer:
composer require imhayatunnabi/laravel-hashes
The package will automatically register its service provider.
Usage
- Add the
HasEncryptedAttributestrait to your model:
use Imhayatunnabi\LaravelHashes\Traits\HasEncryptedAttributes; class User extends Model { use HasEncryptedAttributes; /** * The attributes that should be encrypted. * * @var array */ protected $encryptable = [ 'email', 'phone', // Add other attributes you want to encrypt ]; }
- That's it! Now your model attributes will be automatically encrypted when saving to the database and decrypted when retrieving from the database.
Example
// Creating a new user $user = User::create([ 'name' => 'John Doe', 'email' => 'john@example.com', 'phone' => '1234567890' ]); // The email and phone will be automatically encrypted in the database // Retrieving the user $user = User::find(1); echo $user->email; // Will automatically decrypt and show 'john@example.com' echo $user->phone; // Will automatically decrypt and show '1234567890'
Security
The package uses Laravel's built-in encryption facilities, which means:
- It uses the
APP_KEYfrom your.envfile for encryption - It uses AES-256-CBC encryption by default
- All encrypted values are signed with a message authentication code (MAC) to detect any modifications
License
The MIT License (MIT). Please see License File for more information.