PHPackages                             oriamdev/encryption-db-fields - 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. oriamdev/encryption-db-fields

ActiveLibrary

oriamdev/encryption-db-fields
=============================

This package allows two way encryption on all critical fields inside database. Allows search by encrypted field.

15PHP

Since May 29Pushed 3y ago2 watchersCompare

[ Source](https://github.com/OriamDev/encryption-db-fields)[ Packagist](https://packagist.org/packages/oriamdev/encryption-db-fields)[ RSS](/packages/oriamdev-encryption-db-fields/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Encryption DB Fields
====================

[](#encryption-db-fields)

*This package allows two way encryption on all critical fields inside the database.*
------------------------------------------------------------------------------------

[](#this-package-allows-two-way-encryption-on-all-critical-fields-inside-the-database)

*Allows search by encrypted field.*
-----------------------------------

[](#allows-search-by-encrypted-field)

### Installation

[](#installation)

You can install the package via composer:

```
composer require oriamdev/encryption-db-fields
```

### Setup Eloquent Model

[](#setup-eloquent-model)

**1** - First, you need to add the trait `EncryptAttributesTrait` to the model when you want to encrypt fields.

```
    use EncryptAttributesTrait;
```

**2** - Define the array with fields to be encrypted

```
    protected array $encrypts = ['name', 'email'];
```

**3** - If you want to search by encrypted field you need to add the array `$searchableEncrypts` to the model.

```
    protected array $searchableEncrypts = ['name', 'email'];
```

### Adapt DB Table structure

[](#adapt-db-table-structure)

***NOTES:***

- The fields to be encrypted need to be text type.
- For each searchable field you need to add a string field to migration with name `field_signature`

```
Schema::create('users', function (Blueprint $table) {
    $table->id();
    $table->text('name');
    $table->text('email');
    $table->string('email_signature',10)->index();
    $table->string('name_signature', 10)->index();
    $table->timestamp('email_verified_at')->nullable();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
});
```

### Migrate database

[](#migrate-database)

```
php artisan migrate
```

### CRUD Operations

[](#crud-operations)

The crud operations work the same way and the process to encrypt and decrypt fields are responsibility of the trait `EncryptAttributesTrait`

### Validation Rules

[](#validation-rules)

The *laravel* validation rules `unique and exists` does not work but, not worry about it. The package has a Validation Rule `Oriamdev\EncryptionUserDbAuth\Rules\Encrypted`The construct need the fully qualified name of the model. `User::class or Post::class`

### Check if field under validation is unique

[](#check-if-field-under-validation-is-unique)

After creating the new instance of Encrypted Rule you can pass the unique method

```
$request->validate([
     'email' => [(new Encrypted(User::class))->unique()],
]);
```

If the validation fails the rule return the default value of `validation:unique`

### Check if field under validation exists

[](#check-if-field-under-validation-exists)

After creating the new instance of Encrypted Rule you can pass the exists method

```
$request->validate([
     'email' => [(new Encrypted(User::class))->unique()],
]);
```

If the validation fails the rule return the default value of `validation:unique`

```
$request->validate([
    'name' => [(new Encrypted(User::class))->exists()]
]);
```

### Search by encrypted field

[](#search-by-encrypted-field)

```
$user = User::findByEncrypt('email', 'mario@oriamdev.com');
```

The method `findByEncrypt` return an instance of model or `null` if not exists.

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity26

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/6a6abde2a55a30fa62a9731f5bdd09a3d56f9131be4f845791706862f558957b?d=identicon)[oriamdev](/maintainers/oriamdev)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/oriamdev-encryption-db-fields/health.svg)

```
[![Health](https://phpackages.com/badges/oriamdev-encryption-db-fields/health.svg)](https://phpackages.com/packages/oriamdev-encryption-db-fields)
```

PHPackages © 2026

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