PHPackages                             adityadarma/laravel-database-cryptable - 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. adityadarma/laravel-database-cryptable

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

adityadarma/laravel-database-cryptable
======================================

Cryptable value database for laravel

1.0.1(1y ago)114MITPHPPHP ^8.0

Since May 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/adityadarma/laravel-database-cryptable)[ Packagist](https://packagist.org/packages/adityadarma/laravel-database-cryptable)[ Docs](https://github.com/adityadarma/laravel-database-cryptable)[ RSS](/packages/adityadarma-laravel-database-cryptable/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (5)Used By (0)

Laravel Database Cryptable
==========================

[](#laravel-database-cryptable)

Laravel Database Encryption to safety your data.

### Laravel Installation Instructions

[](#laravel-installation-instructions)

From your projects root folder in terminal run:

```
composer require adityadarma/laravel-database-cryptable
```

### Support

[](#support)

- MYSQL
- MariaDB
- PostgreSQL (required extension pgcrypto)

### Usage

[](#usage)

Use the `CryptableAttribute` trait in any Eloquent model that you wish to apply encryption to and define a `protected $encryptable` array containing a list of the attributes to encrypt.

For example:

```

    use AdityaDarma\LaravelDatabaseCryptable\Traits\CryptableAttribute;

    class User extends Eloquent {
        use CryptableAttribute;

        /**
         * The attributes that should be encrypted on save.
         *
         * @var array
         */
        protected $encryptable = [
            'first_name', 'last_name'
        ];
    }
```

By including the `CryptableAttribute` trait, the `setAttribute()`, `getAttribute()` and `getAttributeFromArray()`methods provided by Eloquent are overridden to include an additional step.

### Searching Encrypted Fields Example:

[](#searching-encrypted-fields-example)

Searching encrypted field can be done by calling the `whereEncrypted` and `orWhereEncrypted` functions similar to laravel eloquent `where` and `orWhere`. Ordering encrypted data can be calling `orderByEncrypted` laravel eloquent `orderBy`.

```
    namespace App\Http\Controllers;

    use App\Models\User;
    class UsersController extends Controller {
        public function index(Request $request)
        {
            $user = User::whereEncrypted('first_name','john')
                        ->orWhereEncrypted('last_name','!=','Doe')
                        ->orderByEncrypted('last_name', 'asc')
                        ->firstOrFail();

            return $user;
        }
    }
```

### Encrypt your current data

[](#encrypt-your-current-data)

If you have current data in your database you can encrypt it with the: `php artisan crypt:encrypt User` command.

Additionally you can decrypt it using the: `php artisan crypt:decrypt 'User` command.

Note: You must implement first the `CryptableAttribute` trait and set `$encryptable` attributes

### Exists and Unique Validation Rules

[](#exists-and-unique-validation-rules)

If you are using exists and unique rules with encrypted values replace it with exists\_encrypted and unique\_encrypted `php $validator = validator(['email'=>'foo@bar.com'], ['email'=>'unique_encrypted:users,email']); `

#### Can I encrypt all my `User` model data?

[](#can-i-encrypt-all-my-user-model-data)

Aside from IDs you can encrypt everything you wan't

For example: Logging-in on encrypted email

```
$user = User::whereEncrypted('email','test@gmail.com')->filter(function ($item) use ($request) {
        return Hash::check($password, $item->password);
    })->where('active',1)->first();

```

Credits
-------

[](#credits)

This package was inspired from the following:

- [austinheap/laravel-database-encryption](https://github.com/austinheap/laravel-database-encryption)
- [magros/laravel-model-encryption](https://github.com/magros/laravel-model-encryption)
- [DustApplication/laravel-database-model-encryption](https://github.com/DustApplication/laravel-database-model-encryption.git)
- [elgiborsolution/laravel-database-encryption](https://github.com/elgiborsolution/laravel-database-encryption)
- [NdukZ/laravel-database-encryption-pgsql](https://github.com/NdukZ/laravel-database-encryption-pgsql)

License
-------

[](#license)

This Package is licensed under the MIT license. Enjoy!

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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 ~20 days

Total

4

Last Release

659d ago

Major Versions

1.x-dev → 2.x-dev2024-07-19

### Community

Maintainers

![](https://www.gravatar.com/avatar/c191e4f4df3ed98299999ab1cf1284ce4b63f1f24ad9f4426b3252f8359fcd15?d=identicon)[adityadarma](/maintainers/adityadarma)

---

Top Contributors

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

---

Tags

laraveldatabase cryptablelaravel cryptableencrypt decrypt

### Embed Badge

![Health badge](/badges/adityadarma-laravel-database-cryptable/health.svg)

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

###  Alternatives

[tpetry/laravel-postgresql-enhanced

Support for many missing PostgreSQL specific features

9982.0M14](/packages/tpetry-laravel-postgresql-enhanced)[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[biiiiiigmonster/hasin

Laravel framework relation has in implement

154552.4k](/packages/biiiiiigmonster-hasin)[dragon-code/laravel-deploy-operations

Performing any actions during the deployment process

240173.5k2](/packages/dragon-code-laravel-deploy-operations)[bavix/laravel-clickhouse

Eloquent model for ClickHouse

72214.1k2](/packages/bavix-laravel-clickhouse)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2928.9k7](/packages/stayallive-laravel-eloquent-observable)

PHPackages © 2026

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