PHPackages                             swisnl/laravel-encrypted-data - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. swisnl/laravel-encrypted-data

ActiveLibrary[File &amp; Storage](/categories/file-storage)

swisnl/laravel-encrypted-data
=============================

Laravel Utilities for Encrypted Data

2.3.0(1y ago)06.4k—8.3%1MITPHPPHP ^8.1CI passing

Since Jun 1Pushed 2mo ago1 watchersCompare

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

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

Laravel Utilities for Encrypted Data
====================================

[](#laravel-utilities-for-encrypted-data)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d8940a254d791bef850560147372cbb7b88079f52c1863b57f7d39fc63e90956/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737769736e6c2f6c61726176656c2d656e637279707465642d646174612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/swisnl/laravel-encrypted-data)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Buy us a tree](https://camo.githubusercontent.com/cec0a9b35a1c3235bdbe0d13ea8fbd866a23e30280ad6ca27078c1fd4ac1b709/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54726565776172652d2546302539462538432542332d6c69676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://plant.treeware.earth/swisnl/laravel-encrypted-data)[![Build Status](https://camo.githubusercontent.com/912a067f690b4d481b22508947846cbe65bf5873aef31c5a17224432aadd1ae6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f737769736e6c2f6c61726176656c2d656e637279707465642d646174612f74657374732e796d6c3f6c6162656c3d7465737473266272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/swisnl/laravel-encrypted-data/actions/workflows/tests.yml)[![Coverage Status](https://camo.githubusercontent.com/a736bd85abd058a033fd399b4a44b9c5ab493ba1932ae753ede3a432a098ae3c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f737769736e6c2f6c61726176656c2d656e637279707465642d646174612e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/swisnl/laravel-encrypted-data/code-structure)[![Quality Score](https://camo.githubusercontent.com/3c86f30f80258fac63079b8e0a91fdf084958c3f68ff8cd7c9f902bb8fb6758f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f737769736e6c2f6c61726176656c2d656e637279707465642d646174612e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/swisnl/laravel-encrypted-data)[![Total Downloads](https://camo.githubusercontent.com/298066db393c7e03e3abfdee399de91d5138081cc958abb959056ccd97b75dbe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f737769736e6c2f6c61726176656c2d656e637279707465642d646174612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/swisnl/laravel-encrypted-data)[![Made by SWIS](https://camo.githubusercontent.com/ef6bdd6ab8d4f47bceb74dcf558b0915c6b419cbba320096324af0518e43091d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2546302539462539412538302d6d6164652532306279253230535749532d2532333037333741392e7376673f7374796c653d666c61742d737175617265)](https://www.swis.nl)

This package contains several Laravel utilities to work with encrypted data.

Install
-------

[](#install)

Via Composer

```
composer require swisnl/laravel-encrypted-data
```

Usage
-----

[](#usage)

### Eloquent casts

[](#eloquent-casts)

Warning

Older versions of this package needed a custom model class to encrypt data. This is now replaced with custom casts. Please see [UPGRADING](UPGRADING.md) for a step-by-step guide on how to migrate.

You can use the Eloquent casts provided by this package just like any other cast. Encryption/decryption is handled automatically behind the scenes.

#### Boolean

[](#boolean)

```
protected $casts = [
    'boolean' => \Swis\Laravel\Encrypted\Casts\AsEncryptedBoolean::class,
];
```

#### Datetime

[](#datetime)

```
protected $casts = [
    'date' => \Swis\Laravel\Encrypted\Casts\AsEncryptedDate::class,
    'datetime' => \Swis\Laravel\Encrypted\Casts\AsEncryptedDateTime::class,
    'immutable_date' => \Swis\Laravel\Encrypted\Casts\AsEncryptedImmutableDate::class,
    'immutable_datetime' => \Swis\Laravel\Encrypted\Casts\AsEncryptedImmutableDateTime::class,
    'date_with_custom_format' => \Swis\Laravel\Encrypted\Casts\AsEncryptedDate::format('Y-m-d'),
];
```

#### Numeric

[](#numeric)

```
protected $casts = [
    'float' => \Swis\Laravel\Encrypted\Casts\AsEncryptedFloat::class,
    'integer' => \Swis\Laravel\Encrypted\Casts\AsEncryptedInteger::class,
];
```

### Filesystem

[](#filesystem)

This package provides a filesystem driver named `encrypted`, which transparently wraps another disk. You can continue using Laravel's standard storage methods and encryption/decryption is handled automatically behind the scenes.

To configure the `encrypted` driver, update `config/filesystems.php` with either a full inline disk configuration:

```
'disks' => [
    'local' => [
        'driver' => 'encrypted',
        'disk' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],
    ],
],
```

Or reference an existing disk by name:

```
'disks' => [
    'local' => [
        'driver' => 'local',
        'root' => storage_path('app'),
    ],

    'local-encrypted' => [
        'driver' => 'encrypted',
        'disk' => 'local',
    ],
],
```

### Commands

[](#commands)

This package provides Artisan commands to help you re-encrypt your data after [rotating your encryption key](https://laravel.com/docs/12.x/encryption#gracefully-rotating-encryption-keys). You want to run these commands because Laravel only re-encrypts data when a value actually changes. This means that after rotating your encryption key, all existing data remains encrypted with the old key until it is updated. If your previous key is ever compromised, or you want to ensure all data uses the new key, you need to re-encrypt everything. These commands automate that process, making sure all your data is protected with the latest encryption key.

Important

Before running these commands, ensure you have rotated your encryption key and have set the `APP_PREVIOUS_KEYS` environment variable with your previous encryption key(s).

#### Re-encrypt models

[](#re-encrypt-models)

Re-encrypts all model attributes that use encrypted casts.

```
php artisan encrypted-data:re-encrypt:models
```

Options:

- `--model=`: Specify one or more model class names to re-encrypt. Auto-detects models if not provided.
- `--except=`: Exclude one or more model class names from re-encryption.
- `--path=`: Path(s) to directories where models are located. Falls back to Models directory if not provided.
- `--casts=`: Regex to match casts that should be re-encrypted.
- `--chunk=`: Number of models to process per chunk.
- `--quietly`: Re-encrypt models without raising events.
- `--no-touch`: Do not update timestamps when saving.
- `--with-trashed`: Include soft-deleted models.
- `--force`: Run without confirmation.
- `--verbose`: Be more verbose about what the command is doing.

#### Re-encrypt files

[](#re-encrypt-files)

Re-encrypts all files on encrypted disks.

```
php artisan encrypted-data:re-encrypt:files
```

Options:

- `--disk=`: Specify one or more disks to re-encrypt. Auto-detects disks if not provided.
- `--dir=`: Directories (within the disk) to scan for files. Defaults to root if not provided.
- `--except=`: Files or directories (within the disk) to exclude.
- `--force`: Run without confirmation.
- `--verbose`: Be more verbose about what the command is doing.

Known issues/limitations
------------------------

[](#known-issueslimitations)

Due to the encryption, some issues/limitations apply:

1. Encrypted data is — depending on what you encrypt — roughly 30-40% bigger.

### Casts

[](#casts)

1. You can't query or order columns that are encrypted in your SQL-statements, but you can query or sort the results using collection methods.

### Filesystem

[](#filesystem-1)

1. You can't use the public disk as that will download the raw encrypted files, so using `Storage::url()` and `Storage::temporaryUrl()` does not make sense;
2. You can use streams with this disk, but internally we will always convert those to strings because the entire file contents need to be encrypted/decrypted at once.

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
composer test
```

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

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

Credits
-------

[](#credits)

- [Jasper Zonneveld](https://github.com/swisnl)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/swisnl/laravel-encrypted-data) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

SWIS ❤️ Open Source
-------------------

[](#swis-heart-open-source)

[SWIS](https://www.swis.nl) is a web agency from Leiden, the Netherlands. We love working with open source software.

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance68

Regular maintenance activity

Popularity25

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 96% 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 ~250 days

Recently: every ~281 days

Total

8

Last Release

60d ago

Major Versions

1.x-dev → 2.0.02022-02-10

2.x-dev → 3.0.0-beta2026-03-19

PHP version history (4 changes)1.0.0PHP ^7.2|^8.0

2.0.0PHP ^8.0

2.3.0PHP ^8.1

3.0.0-betaPHP ^8.2

### Community

Maintainers

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

---

Top Contributors

[![JaZo](https://avatars.githubusercontent.com/u/3475007?v=4)](https://github.com/JaZo "JaZo (96 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (4 commits)")

---

Tags

encryptionfilesystemhacktoberfestlaravelfilesystemlaravellocalswisnlencrypted

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[oneduo/nova-file-manager

A handy file manager tool for Laravel Nova

157350.3k2](/packages/oneduo-nova-file-manager)[singlequote/laravel-webdav

1344.8k](/packages/singlequote-laravel-webdav)[yoelpc4/laravel-cloudinary

Laravel Cloudinary filesystem cloud driver.

3343.0k](/packages/yoelpc4-laravel-cloudinary)[bringyourownideas/laravel-backblaze

Backblaze B2 Cloud Storage for Laravel 5. Original by Paul Olthof (@hpolthof) continued by @bringyourownideas

1237.8k](/packages/bringyourownideas-laravel-backblaze)

PHPackages © 2026

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