PHPackages                             striderwhite/encryptable - 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. striderwhite/encryptable

ActiveLibrary

striderwhite/encryptable
========================

A Laravel trait for encrypting and decrypting model attributes using MySQL AES encryption.

v1.0.0(1y ago)52MITPHPPHP &gt;=8.0

Since Apr 12Pushed 1y ago1 watchersCompare

[ Source](https://github.com/striderwhite/encryptable)[ Packagist](https://packagist.org/packages/striderwhite/encryptable)[ RSS](/packages/striderwhite-encryptable/feed)WikiDiscussions main Synced 1mo ago

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

🔒 Encryptable
=============

[](#-encryptable)

A Laravel trait for automatically encrypting and decrypting model attributes using MySQL AES encryption.

✨ **Features:**

- Models attributes that are marked as `encryptable` will automatically be AES encrypted upon persisting to the database.
- Attributes are automatically decrypted upon retrieval via Eloquent model attributes or when serializing to JSON/array.
- Provides query builder helper methods for searching on the fields using Eloquent, supports both full and partial searching.

---

🚀 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require striderwhite/encryptable
```

---

📖 Usage
-------

[](#-usage)

1. **Database Setup:** Ensure the database column you wish to encrypt is of `binary` datatype.
2. **Add the Trait:** Add the `Encryptable` trait to your Eloquent model.
3. **Define Encryptable Fields:** Define an `$encryptable` property in your model with the list of attributes to encrypt.

```
use StriderWhite\Encryptable;

class YourModel extends Model
{
    use Encryptable;

    protected $encryptable = ['field1', 'field2'];
}
```

4. 💾 **Persisting and Retrieving Data**

Using the `Encryptable` trait, you can persist and retrieve data just like normal Eloquent attributes. The encryption and decryption process is handled automatically.

#### Example

[](#example)

```
use App\Models\YourModel;

// Persisting data
$model = new YourModel();
$model->field1 = 'Sensitive Data';
$model->field2 = 'Another Secret';
$model->save();

// Retrieving data
$retrievedModel = YourModel::find($model->id);
echo $retrievedModel->field1; // Outputs: Sensitive Data
echo $retrievedModel->field2; // Outputs: Another Secret
```

---

### 🔎 Searching Encrypted Fields

[](#-searching-encrypted-fields)

The package provides two query scopes for searching encrypted fields:

#### `scopeWhereEncrypted`

[](#scopewhereencrypted)

Use this scope to search for an exact match on an encrypted field:

```
YourModel::whereEncrypted('field1', 'value')->get();
```

#### `scopeWhereEncryptedLike`

[](#scopewhereencryptedlike)

Use this scope to perform a partial search on an encrypted field:

```
YourModel::whereEncryptedLike('field1', 'value')->get();
```

---

🙏 Credits
---------

[](#-credits)

Developed and maintained by **Strider White**. If you find this package helpful, feel free to ⭐ the repository or contribute!

---

📜 License
---------

[](#-license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance46

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

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

Unknown

Total

1

Last Release

401d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0d51d21024846ee453aa8b96924826edd83907fe6d093256fabc21c5d44b3434?d=identicon)[1337SW1337](/maintainers/1337SW1337)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/striderwhite-encryptable/health.svg)

```
[![Health](https://phpackages.com/badges/striderwhite-encryptable/health.svg)](https://phpackages.com/packages/striderwhite-encryptable)
```

###  Alternatives

[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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