PHPackages                             h-farm/laravel-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. [Database &amp; ORM](/categories/database)
4. /
5. h-farm/laravel-encryptable

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

h-farm/laravel-encryptable
==========================

Laravel Encryptable

4.0.0(6mo ago)13420814[1 issues](https://github.com/maize-tech/laravel-encryptable/issues)[4 PRs](https://github.com/maize-tech/laravel-encryptable/pulls)MITPHPPHP ^8.2CI passing

Since Jun 25Pushed 1mo ago5 watchersCompare

[ Source](https://github.com/maize-tech/laravel-encryptable)[ Packagist](https://packagist.org/packages/h-farm/laravel-encryptable)[ Docs](https://github.com/maize-tech/laravel-encryptable)[ GitHub Sponsors](https://github.com/maize-tech)[ RSS](/packages/h-farm-laravel-encryptable/feed)WikiDiscussions main Synced today

READMEChangelog (9)Dependencies (11)Versions (14)Used By (0)

   ![Social Card of Laravel Encryptable](/art/socialcard-light.png)

Laravel Encryptable
===================

[](#laravel-encryptable)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b0be659ccd303087c447209ed30d1d9bc9fa8b935572513738357f80c77b41fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d61697a652d746563682f6c61726176656c2d656e637279707461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/maize-tech/laravel-encryptable)[![GitHub Tests Action Status](https://camo.githubusercontent.com/3687f0d81443f3a260893c0f0c7675c755bf9aa507c10150cccefdf83d777aab/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d61697a652d746563682f6c61726176656c2d656e637279707461626c652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/maize-tech/laravel-encryptable/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/756b7f799e0ebca6206827381bb55ede627b4916ba9c31c91976147819606586/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d61697a652d746563682f6c61726176656c2d656e637279707461626c652f7068702d63732d66697865722e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/maize-tech/laravel-encryptable/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/e41748396b44d429bc2e473c2806c4c3daf4ef9baf604bd5b47820b723481256/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d61697a652d746563682f6c61726176656c2d656e637279707461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/maize-tech/laravel-encryptable)

This package allows you to anonymize sensitive data (like the name, surname and email address of a user) similarly to Laravel's Encryption feature, but still have the ability to make direct queries to the database. An example use case could be the need to make search queries through anonymized attributes.

This package currently supports `MySQL` and `PostgreSQL` databases.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require maize-tech/laravel-encryptable
```

You can publish the config file with:

```
php artisan vendor:publish --provider="Maize\Encryptable\EncryptableServiceProvider" --tag="encryptable-config"
```

This is the content of the published config file:

```
return [
    /*
    |--------------------------------------------------------------------------
    | Encryption key
    |--------------------------------------------------------------------------
    |
    | The key used to encrypt data.
    | Once defined, never change it or encrypted data cannot be correctly decrypted.
    |
    */

    'key' => env('ENCRYPTION_KEY'),

    /*
    |--------------------------------------------------------------------------
    | Encryption cipher
    |--------------------------------------------------------------------------
    |
    | The cipher used to encrypt data.
    | Once defined, never change it or encrypted data cannot be correctly decrypted.
    | Default value is the cipher algorithm used by default in MySQL.
    |
    */

    'cipher' => env('ENCRYPTION_CIPHER', 'aes-128-ecb'),
];
```

Usage
-----

[](#usage)

### Basic

[](#basic)

To use the package, just add the `Encryptable` cast to all model attributes you want to anonymize.

```
