PHPackages                             ionghitun/laravel-lumen-mysql-encryption - 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. [Database &amp; ORM](/categories/database)
4. /
5. ionghitun/laravel-lumen-mysql-encryption

AbandonedArchivedLibrary[Database &amp; ORM](/categories/database)

ionghitun/laravel-lumen-mysql-encryption
========================================

Database fields encryption in laravel and lumen for mysql databases with native search and anonymize data for gdpr.

4.5.0(3y ago)195.1k↓30.6%21MITPHPPHP &gt;=8.0

Since Dec 15Pushed 3y ago2 watchersCompare

[ Source](https://github.com/ionghitun/laravel-lumen-mysql-encryption)[ Packagist](https://packagist.org/packages/ionghitun/laravel-lumen-mysql-encryption)[ Docs](https://github.com/ionghitun/laravel-lumen-mysql-encryption)[ RSS](/packages/ionghitun-laravel-lumen-mysql-encryption/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (25)Used By (1)

[![Latest Stable Version](https://camo.githubusercontent.com/a08527e3b29baa2394289d98a59f0f662dfdd3e4cb6ab6ee7edb4f6e4380daf5/68747470733a2f2f706f7365722e707567782e6f72672f696f6e67686974756e2f6c61726176656c2d6c756d656e2d6d7973716c2d656e6372797074696f6e2f762f737461626c65)](https://packagist.org/packages/ionghitun/laravel-lumen-mysql-encryption)[![Build Status](https://camo.githubusercontent.com/8bbef5449032534a8f933d1e5d79a8b3906366763dcb17f9943d5fa19162565d/68747470733a2f2f7472617669732d63692e636f6d2f696f6e67686974756e2f6c61726176656c2d6c756d656e2d6d7973716c2d656e6372797074696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/ionghitun/laravel-lumen-mysql-encryption)[![Total Downloads](https://camo.githubusercontent.com/937f4b78217136878ed215d6aed74d590f19374596114565314755c6eefb6a64/68747470733a2f2f706f7365722e707567782e6f72672f696f6e67686974756e2f6c61726176656c2d6c756d656e2d6d7973716c2d656e6372797074696f6e2f646f776e6c6f616473)](https://packagist.org/packages/ionghitun/laravel-lumen-mysql-encryption)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/fd66259f114d36fc5cd335629619e4b42cb2d98c356cc910afa4ba54dae6a86e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f696f6e67686974756e2f6c61726176656c2d6c756d656e2d6d7973716c2d656e6372797074696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ionghitun/laravel-lumen-mysql-encryption/?branch=master)[![License](https://camo.githubusercontent.com/d958f77c02f3d50e3a0c061021d857fc7484b37385f43a5193f888298081304f/68747470733a2f2f706f7365722e707567782e6f72672f696f6e67686974756e2f6c61726176656c2d6c756d656e2d6d7973716c2d656e6372797074696f6e2f6c6963656e7365)](https://packagist.org/packages/ionghitun/laravel-lumen-mysql-encryption)

Laravel Mysql Encryption
========================

[](#laravel-mysql-encryption)

Database fields encryption in laravel and lumen for mysql databases with native search and anonymize data.

Instalation notes
-----------------

[](#instalation-notes)

`$ composer require ionghitun/laravel-lumen-mysql-encryption`

Dependencies
------------

[](#dependencies)

- php &gt;= 8.0

Documentation:
--------------

[](#documentation)

Service provider is automatically loaded for laravel, for lumen you need to add

```
$app->register(IonGhitun\MysqlEncryption\MysqlEncryptionServiceProvider::class);

```

to your `bootstrap/app.php` file.

You need to add `ENCRYPTION_KEY` to your `.env` file, has to be 16 chars long.

Each of your Models should extend `IonGhitun\MysqlEncryption\Models\BaseModel` and for the fields you want to be encrypted you have to do the following:

- in migrations set field to `binary`
- add `$encrypted` to your model:

    ```
      /** @var array */
      protected $encrypted = [
          'name',
          'email'
      ];

    ```

You can use Validator on these fields with:

- unique\_encrypted

    ```
      unique_encrypted:,

    ```
- exists\_encrypted

    ```
      exists_encrypted:,

    ```

You cannot use basic where, orWhere, orderBy on encrypted fields so there are 5 predefined scopes that you can use as a replacer:

```
  - whereEncrypted
  - whereNotEncrypted
  - orWhereEncrypted
  - orWhereNotEncrypted
  - orderByEncrypted

```

Possibility to anonymize data:

- set `$anonymizable` variable on your model, the data will be anonymized using , for all the types available check this package.

Example:

```
    //without extra parameters needed for randomDigit
    protected $anonymizable = [
        'age' => ['randomDigit']
    ];

    //with extra parameters needed for numberBetween
    protected $anonymizable = [
        'age' => ['numberBetween', '18','50']
    ];

```

- get your model instance and use anonymize method: `$user->anonymize();`

The method accepts a locale parameter, if you want to use faker with localization, the default locale can be set in `.env` file: `FAKER_LOCALE = 'en_US'`

If is not specified by any method above, the default Faker local will be used by default

Note: Model is not automatically saved!

*Happy coding!*

In order to revert data encrypted with this package you need to remove columns from the $encrypted array, do a foreach through your models and save the $this-&gt;aesDecrypt($value) for all the columns that were in $encrypted array, then change the column from binary to something more suitable.

After this you can remove the package and extend the basic laravel model, and so cleanup, remove anything related to this package!

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity72

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~41 days

Total

24

Last Release

1386d ago

Major Versions

1.4.1 → 2.0.02020-04-07

2.1.1 → 3.0.02020-12-26

3.0.0 → 4.0.02021-01-25

PHP version history (5 changes)1.0PHP &gt;=7.1

1.1.1PHP &gt;=7.2

3.0.0PHP &gt;=7.3

4.1.1PHP &gt;=7.4

4.2.0PHP &gt;=8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13887807?v=4)[Ion Ghitun](/maintainers/ionghitun)[@ionghitun](https://github.com/ionghitun)

---

Top Contributors

[![ionghitun](https://avatars.githubusercontent.com/u/13887807?v=4)](https://github.com/ionghitun "ionghitun (26 commits)")

---

Tags

anonymizedatabase-fields-encryptionlaravellumenmysql-databaseslaravelencryptionlumenmysqlgdpranonymizeionghitun

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ionghitun-laravel-lumen-mysql-encryption/health.svg)

```
[![Health](https://phpackages.com/badges/ionghitun-laravel-lumen-mysql-encryption/health.svg)](https://phpackages.com/packages/ionghitun-laravel-lumen-mysql-encryption)
```

###  Alternatives

[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k33.0M95](/packages/owen-it-laravel-auditing)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k25.2M34](/packages/kirschbaum-development-eloquent-power-joins)[chr15k/laravel-mysql-encrypt

Laravel database encryption using native MySQL functions

119.9k](/packages/chr15k-laravel-mysql-encrypt)[guidocella/eloquent-populator

Guess attributes for Eloquent model factories

7661.6k2](/packages/guidocella-eloquent-populator)[prodigyphp/laravel-ssh-tunnel

Easy creation &amp; maintenance of an SSH Tunnel for Laravel

3930.9k](/packages/prodigyphp-laravel-ssh-tunnel)

PHPackages © 2026

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