Laravel Utilities for Encrypted Data

2.1.0 2023-02-16 20:28 UTC

This package is auto-updated.

Last update: 2023-03-16 20:41:24 UTC


Latest Version on Packagist Software License Buy us a tree Build Status Coverage Status Quality Score Total Downloads Made by SWIS

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


Via Composer

$ composer require swisnl/laravel-encrypted-data

N.B. Using Laravel 6-8? Please use version 1.x of this package.



Extend \Swis\Laravel\Encrypted\EncryptedModel in your model and define the encrypted fields. Make sure your database columns are long enough, so your data isn't truncated!

protected $encrypted = [

You can now simply use the model properties as usual and everything will be encrypted/decrypted under the hood!


Configure the storage driver in config/filesystems.php.

'disks' => [
    'local' => [
        'driver' => 'local-encrypted',
        'root' => storage_path('app'),

You can now simply use the storage methods as usual and everything will be encrypted/decrypted under the hood!

Known issues/limitations

Due to the encryption, some issues/limitations apply:

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


  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;
  2. All data is being serialized before it is encrypted — and unserialized after it is decrypted — so everything is stored exactly as how Laravel would insert it into the database. You can use Eloquent Mutators as you normally would.


  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

Please see CHANGELOG for more information on what has changed recently.


$ composer test


Please see CONTRIBUTING and CODE_OF_CONDUCT for details.


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



The MIT License (MIT). Please see License File for more information.

This package is Treeware. If you use it in production, then we ask that you buy the world a tree 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 is a web agency from Leiden, the Netherlands. We love working with open source software.