PHPackages                             wellingtoncarneirobarbosa/laravel-encrypt-database - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. wellingtoncarneirobarbosa/laravel-encrypt-database

ActiveLibrary

wellingtoncarneirobarbosa/laravel-encrypt-database
==================================================

Auto Encrypt and Decrypt Database through Eloquent

328PHP

Since Oct 21Pushed 2y ago2 watchersCompare

[ Source](https://github.com/WellingtonCarneiroBarbosa/laravel-encrypt-database)[ Packagist](https://packagist.org/packages/wellingtoncarneirobarbosa/laravel-encrypt-database)[ RSS](/packages/wellingtoncarneirobarbosa-laravel-encrypt-database/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Update
======

[](#update)

Currently, laravel has a model cast called "encrypted". Just use the cast, its easier and most efficient.

e.g:

```
//YourModel.php
protected $casts = [
'your_encrypted_field' => 'encrypted',
];
```

Laravel Encrypt Database
========================

[](#laravel-encrypt-database)

Automatic Encrypt and Decrypt your database data. Tested and used on Laravel 8.

Important
---------

[](#important)

- Note the key used to encrypt your data is your `app_key`, so keep it in a secure place.
- If you lose it, you will lose all your database data.

- The $casts attribute is not available for encrypted fields yet.

- It is highly recommended to alter your encrypted column types to `TEXT` or `LONGTEXT`

Features
--------

[](#features)

- Minimal configuration
- Encrypt and Decrypt database fields easily
- Include searching encrypted data using the following: whereEncrypted and orWhereEncrypted
- Include unique\_encrypted, exists\_encrypted rules
- Uses openssl for encrypting and decrypting fields

Requirements
------------

[](#requirements)

Laravel &gt;= 8.0
PHP &gt;= 7.4

Installing
----------

[](#installing)

Install the package

```
composer require wellingtoncarneirobarbosa/laravel-encrypt-database

```

Add the service provider on your providers list config/app.php:168

```
WellingtonCarneiroBarbosa\EncryptDatabase\Providers\EncryptDatabaseProvider::class,

```

Publish the config file

```
php artisan vendor:publish --tag=laravel-database-encryption

```

Usage
-----

[](#usage)

Just use the trait on yours encryptables models and list the encryptable fields.

```
use WellingtonCarneiroBarbosa\EncryptDatabase\Traits\EncryptableModel;

class User extends Authenticable
{
    Use HasFactory,
        EncryptableModel;

    /**
    * The attributes that should be encrypted.
    *
    * @var array
    */
    protected $encryptable = [
        'name',
        'email',
        'birth_date',
    ];
}

```

Note if you have a mutator on your model like "setNameAttribute" you should implement manually the encrypt method ```
public function setNameAttribute(string $value)
{
  $value = ucwords($value);

  $this->attributes['name'] = $this->encrypt('name', $value);
}

```

You also should implement manually decrypt method if you have an acessor method ```
public function getNameAttribute()
{
  $decrypted = $this->decrypt('name', $this->attributes['name']);

  $value = strtolower($decrypted);

  return $value;
}

```

If you are validating your form data with `unique` or `exists` you should replace it to `unique_encrypted` and `exists_encrypted` respectively

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity20

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/76abe486015400eec81f39ad9c01a06fb5e42fb678136bf3b0d614c15c58ee53?d=identicon)[owellcarneiro](/maintainers/owellcarneiro)

---

Top Contributors

[![WellingtonCarneiroBarbosa](https://avatars.githubusercontent.com/u/56309143?v=4)](https://github.com/WellingtonCarneiroBarbosa "WellingtonCarneiroBarbosa (55 commits)")

### Embed Badge

![Health badge](/badges/wellingtoncarneirobarbosa-laravel-encrypt-database/health.svg)

```
[![Health](https://phpackages.com/badges/wellingtoncarneirobarbosa-laravel-encrypt-database/health.svg)](https://phpackages.com/packages/wellingtoncarneirobarbosa-laravel-encrypt-database)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
