PHPackages                             henzeb/laravel-encrypted-data-rotator - 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. henzeb/laravel-encrypted-data-rotator

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

henzeb/laravel-encrypted-data-rotator
=====================================

Rotates your encrypted data.

v0.3.0-alpha(1y ago)11AGPL-3.0-onlyPHPPHP ^8.1

Since Aug 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/henzeb/laravel-encrypted-data-rotator)[ Packagist](https://packagist.org/packages/henzeb/laravel-encrypted-data-rotator)[ Docs](https://github.com/henzeb/laravel-encrypted-values-rotator)[ RSS](/packages/henzeb-laravel-encrypted-data-rotator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (6)Versions (6)Used By (0)

Encrypted data rotator for Laravel 11+
======================================

[](#encrypted-data-rotator-for-laravel-11)

[![Build Status](https://github.com/henzeb/laravel-encrypted-data-rotator/workflows/tests/badge.svg)](https://github.com/henzeb/laravel-encrypted-data-rotator/actions)[![Latest Version on Packagist](https://camo.githubusercontent.com/cc031c1b30132d0493107c726f7836f77ed4e27be3315fcf2a0664dc7a8c9055/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68656e7a65622f6c61726176656c2d656e637279707465642d646174612d726f7461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/henzeb/laravel-encrypted-data-rotator)[![Total Downloads](https://camo.githubusercontent.com/7fe0f2e610b69616aea1c6b0f73f5943315c9a1e4435f56d2f4e635c8bb07761/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68656e7a65622f6c61726176656c2d656e637279707465642d646174612d726f7461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/henzeb/laravel-encrypted-data-rotator)[![License](https://camo.githubusercontent.com/7fdaf6fafc4e41c9aab57bec9c5e9a247ad16c9c5a3f479bee4fe37e306c08b5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f68656e7a65622f6c61726176656c2d656e637279707465642d646174612d726f7461746f72)](https://packagist.org/packages/henzeb/laravel-encrypted-data-rotator)

Laravel 11 comes with app key rotation. Sadly, at this point, laravel won't re-encrypt the data unless a user changes it.

This package allows you to rotate Models by default, but also allows you to rotate your own custom encrypted data.

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

[](#installation)

Just install with the following command.

```
composer require henzeb/laravel-encrypted-data-rotator
```

Usage
-----

[](#usage)

### Configuring

[](#configuring)

You do not need to modify anything when you are just going to rotate the Models. Everything is done automatically for you. Most is configurable by environment variables.

#### Publishing the configuration

[](#publishing-the-configuration)

The configuration file is published with the following command:

```
php artisan vendor:publish --tag=rotator
```

### Rotate the key

[](#rotate-the-key)

Laravel does not come with a handy key rotate command, you need to manually save the key in the `APP_PREVIOUS_KEYS` variable, which you might forget, or simply make mistakes with.

```
php artisan key:rotate
```

You can also select a different environment.

```
php artisan key:rotate --env your-env
```

On production, you are being asked if you want to rotate the keys. you can force this.

```
php artisan key:rotate --force
```

### Rotate your data

[](#rotate-your-data)

When you have rotated the key, the encrypted data hasn't changed yet. Laravel will use the previous keys if the current one cannot decrypt the data. Using the following the data will also be rotated.

```
php artisan key:rotate-data
```

You do not have to do anything on the Models. The Models and their encrypted attributes are automatically detected.

Note: just like the key rotation command, `key:rotate-data` accepts `env` to specify an environment and `force` to start rotation without confirmation.

#### Rotating mutators

[](#rotating-mutators)

If you have mutators in your model that handles encrypted data, you want them to be rotated as well. For those situations you can use the Attribute `EncryptsData`. The `key:rotate-data` command will then detect the mutator and rotate its data.

```
use Henzeb\Rotator\Attributes\EncryptsData;

#[EncryptsData]
public function myAttribute(): Attribute
{
    return Attribute::set(
        fn($value) => encrypt($value)
    )->get(fn($value) => decrypt($value));
}
```

#### Rotating custom attribute casts

[](#rotating-custom-attribute-casts)

It is possible to rotate custom casts. Your `CastsAttributes` implementation should either have `encrypted` in its class name, or implement the `Henzeb\Rotator\Contracts\CastsEncryptedAttributes` interface.

```
use Henzeb\Rotator\Contracts\CastsEncryptedAttributes;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;

class YourCustomAttribute implements CastsAttributes, CastsEncryptedAttributes
{
    // your implementation
}
```

Note: This also works with `CastsInboundAttributes` implementations

#### rotating custom encrypted data

[](#rotating-custom-encrypted-data)

To rotate encrypted data that is not accessible by models, you can implement the `rotateEncryptedData` method on the `\Henzeb\Rotator\Contracts\RotatesEncryptedData`interface. When the default configuration is applied, these implementations are also automatically detected.

#### customize rotation on Models

[](#customize-rotation-on-models)

The `RotatesEncryptedData` interface can also be applied on Models. These are `per-record` basis.

#### Events

[](#events)

For each processed Model, a `ModelEncryptionRotated` event is emitted. It contains the Model for easy access.

Note: For custom implementations, there are no events. You have to implement them yourself.

### Queue

[](#queue)

Everything is done utilizing the queue. By default it uses the default queue and default connection. You can change that by setting the `ROTATOR_QUEUE`and `ROTATOR_QUEUE_CONNECTION`, or the corresponding keys in the configuration file.

To avoid out of memory, the amount of jobs in the given queue is limited by the `ROTATOR_JOB_LIMIT`. Whenever the queue size is too big, the `RotateModelsWithEncryptedData` job will be placed back on the queue waiting for the jobs it had dispatched to finish. This is by default 100 jobs.

To avoid heavy load on your database, you can modify the `ROTATOR_CHUNK_SIZE`. By default, 50 records are pulled from your database and dispatched to the queue.

### Cleaning up previous keys

[](#cleaning-up-previous-keys)

if you rotate regularly, or when you are confident the keys are no longer needed, you can cleanup the keys simply by running the following command:

```
php artisan key:cleanup-previous-keys
```

Note: just like the other commands, `key:cleanup-previous-keys` accepts `env` to specify an environment and `force` to clean up without confirmation.

Testing this package
--------------------

[](#testing-this-package)

```
composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Henze Berkheij](https://github.com/henzeb)

License
-------

[](#license)

The GNU AGPLv. Please see [License File](LICENSE.md) for more information.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

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.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

642d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15928532?v=4)[henzeb](/maintainers/henzeb)[@henzeb](https://github.com/henzeb)

---

Top Contributors

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

---

Tags

laravelsecurityencryptioneloquentkeyrotatekeyshenzebrotation

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/henzeb-laravel-encrypted-data-rotator/health.svg)

```
[![Health](https://phpackages.com/badges/henzeb-laravel-encrypted-data-rotator/health.svg)](https://phpackages.com/packages/henzeb-laravel-encrypted-data-rotator)
```

###  Alternatives

[kodeine/laravel-acl

Light-weight role-based permissions for Laravel 5 built in Auth system.

782354.8k5](/packages/kodeine-laravel-acl)[delatbabel/elocryptfive

Automatically encrypt and decrypt Eloquent attributes with ease.

8493.0k](/packages/delatbabel-elocryptfive)[highsolutions/eloquent-sequence

A Laravel package for easy creation and management sequence support for Eloquent models with elastic configuration.

121130.3k](/packages/highsolutions-eloquent-sequence)[rennokki/eloquent-settings

Eloquent Settings allows you to bind key-value pairs to any Laravel Eloquent model. It supports even casting for boolean, float or integer types.

804.2k](/packages/rennokki-eloquent-settings)[dolphiq/laravel-aescrypt

AES encrypt and decrypt Eloquent attributes inspired by elocryptfive

171.7k](/packages/dolphiq-laravel-aescrypt)[konekt/acl

Concord Module for Permission handling (Laravel 10 - 12)

1070.8k1](/packages/konekt-acl)

PHPackages © 2026

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