PHPackages                             roelofr/laravel-encryption-cast - 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. roelofr/laravel-encryption-cast

AbandonedArchivedLibrary

roelofr/laravel-encryption-cast
===============================

An Eloquent cast to encrypt and decrypt data, whilst still allowing your own casts

v1.2.0(5y ago)21.2kMITPHPPHP ^7.4 || ^8.0

Since Aug 13Pushed 3y agoCompare

[ Source](https://github.com/roelofr/laravel-encryption-cast)[ Packagist](https://packagist.org/packages/roelofr/laravel-encryption-cast)[ RSS](/packages/roelofr-laravel-encryption-cast/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (3)Dependencies (10)Versions (6)Used By (0)

Encryption Cast for Laravel
===========================

[](#encryption-cast-for-laravel)

[![Build status](https://camo.githubusercontent.com/93186d1ab9f06f542d89251e28c31ebaa03258e274147de81139464f95959988/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f726f656c6f66722f6c61726176656c2d656e6372797074696f6e2d636173742f52756e253230756e697425323074657374732e7376673f7374796c653d666c6174)](https://github.com/roelofr/laravel-encryption-cast/actions)[![Code Climate maintainability rating](https://camo.githubusercontent.com/42e54be24c89a12f9a7ccccbfd08f2fd03b5aa7356081a99a9c7ee30e5c2cc8a/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f6d61696e7461696e6162696c6974792f726f656c6f66722f6c61726176656c2d656e6372797074696f6e2d636173742e7376673f6c6162656c3d436f6465436c696d6174652b4d61696e7461696e6162696c697479267374796c653d666c6174)](https://codeclimate.com/github/roelofr/laravel-encryption-cast)[![Code Climate coverage rating](https://camo.githubusercontent.com/14b9fd466b6556ffc39ff47ce6c71b41b18bc3b1aaf09b9a4cbbffcf5237d87d/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f636f7665726167652d6c65747465722f726f656c6f66722f6c61726176656c2d656e6372797074696f6e2d636173742e7376673f7374796c653d666c6174)](https://codeclimate.com/github/roelofr/laravel-encryption-cast)

[![PHP code style: PSR-12](https://camo.githubusercontent.com/8775bc373188ca6684973b1a03ae3d5add835b198db81e25db28dd853bfc2788/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f706870253230636f64652532307374796c652d5053522d2d31322d3838393262652e7376673f7374796c653d666c6174)](https://www.php-fig.org/psr/psr-12/)[![License: MIT](https://camo.githubusercontent.com/fa8e7eccd2a7692d0b48d9b19460da3d838629b8d7e8255e57dd4cc00ee130f2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f726f656c6f66722f6c61726176656c2d656e6372797074696f6e2d636173742e7376673f7374796c653d666c6174)](LICENSE.md)

A super-simple, fully tested database encryption system, which allows for extra conversions to take place afterwards.

End of Life
-----------

[](#end-of-life)

This package has reached it's end of life. [Laravel now supports encryption out-of-the-box](https://laravel.com/docs/9.x/eloquent-mutators#encrypted-casting), so adding a separate package that does the same is useless.

License
-------

[](#license)

The software is licensed under the [MIT License](LICENSE.md).

Requirements
------------

[](#requirements)

This project requires Laravel 7.x and PHP 7.4 or newer. You should also update your database schemas to allow for encrypted data. Encrypted data is base64-encoded, and might be significantly longer than the same data as, for example, JSON.

It's recommended to use long `VARCHAR` fields or even `TEXT` fields.

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

[](#installation)

Just require it via composer, it doesn't register a service provider.

```
composer require roelofr/laravel-encryption-cast

```

Usage
-----

[](#usage)

This class contains a two-way cast that takes extra casts as first and only argument. `null`-values are not encrypted.

### Encrypted strings

[](#encrypted-strings)

To encrypt the `phone_number` field, simply cast it.

```
protected $casts = [
    'phone_number' => \Roelofr\EncryptionCast\Casts\EncryptedAttribute::class
];
```

### Encrypted basic types

[](#encrypted-basic-types)

Say we have a `date_of_birth` field, we can cast that as a date.

```
protected $casts = [
    'date_of_birth' => \Roelofr\EncryptionCast\Casts\EncryptedAttribute::class . ':date'
];
```

### Encrypted collections

[](#encrypted-collections)

Now, say we have an `address` which is a collection, we can also cast it like that.

```
protected $casts = [
    'address' => \Roelofr\EncryptionCast\Casts\EncryptedAttribute::class . ':collection'
];
```

### Encrypted complex models

[](#encrypted-complex-models)

Now, lastly, say you made a [custom cast](https://laravel.com/docs/7.x/eloquent-mutators#custom-casts) that casts the `medication` field to some other type, and named it `App\Casts\MedicationCast`, you can send that as a second argument.

```
protected $casts = [
    'medication' => \Roelofr\EncryptionCast\Casts\EncryptedAttribute::class . ':' . \App\Casts\MedicationCast::class
];
```

And that's about it.

Compatibility
-------------

[](#compatibility)

To ease development you can use one of the casts in the `Compat` namespace. These are included:

- For [`austinheap/laravel-database-encryption`](https://github.com/austinheap/laravel-database-encryption) you can use `AustinHeapEncryptedAttribute`.

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

[](#contributing)

If you found any bugs or issues and can help, please open an issue. The code is linted for code style and coverage is exected to be &gt;95% at all times.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity63

Established project with proven stability

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 ~9 days

Total

4

Last Release

2071d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8996f83ae91f55b9d708a8ef779e7d7301690642ba6c820a5a318d36472a960d?d=identicon)[SirQuack](/maintainers/SirQuack)

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/roelofr-laravel-encryption-cast/health.svg)

```
[![Health](https://phpackages.com/badges/roelofr-laravel-encryption-cast/health.svg)](https://phpackages.com/packages/roelofr-laravel-encryption-cast)
```

###  Alternatives

[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

44643.1k1](/packages/pressbooks-pressbooks)[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)
