PHPackages                             ashallendesign/redactable-models - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ashallendesign/redactable-models

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ashallendesign/redactable-models
================================

A Laravel package for easily redacting model data.

v1.3.1(2mo ago)1143.4k—6.7%3MITPHPPHP ^8.3CI passing

Since Jul 27Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/ash-jc-allen/redactable-models)[ Packagist](https://packagist.org/packages/ashallendesign/redactable-models)[ Docs](https://github.com/ash-jc-allen/redactable-models)[ GitHub Sponsors](https://github.com/ash-jc-allen)[ RSS](/packages/ashallendesign-redactable-models/feed)WikiDiscussions main Synced 1mo ago

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

[![Redactable Models for Laravel](/docs/logo.png)](/docs/logo.png)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e5606fc4a08f006243d5f3d1beec2143d3d3781aff3f229f094b4cfeec003777/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f617368616c6c656e64657369676e2f72656461637461626c652d6d6f64656c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ashallendesign/redactable-models)[![Total Downloads](https://camo.githubusercontent.com/3841dfb9d575c23e541d784e62f8e0c0b13c62bb10e8a74c6041d66c9a0cd479/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f617368616c6c656e64657369676e2f72656461637461626c652d6d6f64656c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ashallendesign/redactable-models)[![PHP from Packagist](https://camo.githubusercontent.com/180ba3c451aa157628a2c76bd09bc7a8f91cd41b03fb379430b4b712a8e06358/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f617368616c6c656e64657369676e2f72656461637461626c652d6d6f64656c733f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ashallendesign/redactable-models)[![GitHub license](https://camo.githubusercontent.com/2cdcdf77bb69565f96f47b8d8ff99434740ebc4ff21daef6c1cdd9fd0018c579/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6173682d6a632d616c6c656e2f72656461637461626c652d6d6f64656c733f7374796c653d666c61742d737175617265)](https://github.com/ash-jc-allen/redactable-models/blob/master/LICENSE.md)

Table of Contents
-----------------

[](#table-of-contents)

- [Overview](#overview)
- [Installation](#installation)
    - [Requirements](#requirements)
    - [Install the Package](#install-the-package)
- [Usage](#usage)
    - [Defining Redactable Models](#defining-redactable-models)
    - [Defining Mass Redactable Models](#defining-mass-redactable-models)
    - [The `model:redact` Command](#the-modelredact-command)
    - [Redaction Strategies](#redaction-strategies)
        - [`ReplaceContents`](#replacecontents)
        - [`HashContents`](#hashcontents)
        - [`MaskContents`](#maskcontents)
        - [Custom Redaction Strategies](#custom-redaction-strategies)
    - [Manually Redacting Models](#manually-redacting-models)
    - [Events](#events)
        - [`ModelRedacted`](#modelredacted)
- [Testing](#testing)
- [Security](#security)
- [Credits](#credits)
- [Changelog](#changelog)
- [License](#license)

Overview
--------

[](#overview)

A Laravel package that you can use to redact, obfuscate, or mask fields from your models in a consistent and easy way.

When building web applications, you'll often need to keep hold of old data for auditing or reporting purposes. But for data privacy and security reasons, you may want to redact the sensitive information from the data that you store. This way, you can keep the rows in the database, but without the sensitive information.

This package allows you to define which models and fields should be redacted, and how they should be redacted.

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

[](#installation)

### Requirements

[](#requirements)

The package has been developed and tested to work with the following minimum requirements:

- PHP 8.3
- Laravel 11

### Install the Package

[](#install-the-package)

You can install the package via Composer:

```
composer require ashallendesign/redactable-models
```

Usage
-----

[](#usage)

### Defining Redactable Models

[](#defining-redactable-models)

In order to make a model redactable, you need to add the `AshAllenDesign\RedactableModels\Interfaces\Redactable` interface to the model. This will enforce two new methods (`redactable` and `redactionStrategy`) that you need to implement.

Your model may look something like so:

```
use AshAllenDesign\RedactableModels\Interfaces\Redactable;
use Illuminate\Contracts\Database\Eloquent\Builder;

class User extends Model implements Redactable
{
    // ...

    public function redactable(): Builder
    {
        // ...
    }

    public function redactionStrategy(): RedactionStrategy
    {
        // ...
    }
}
```

The `redactable` method allows you to return an instance of `Illuminate\Contracts\Database\Eloquent\Builder` which defines the models that are redactable.

The `redactionStrategy` method allows you to return an instance of `AshAllenDesign\RedactableModels\Interfaces\RedactionStrategy` which defines how the fields should be redacted. We'll cover the available strategies further down.

As an example, if we wanted to redact the `email` and `name` fields from all `App\Models\User` models older than 30 days, we could do the following:

```
use AshAllenDesign\RedactableModels\Support\Strategies\ReplaceContents;
use AshAllenDesign\RedactableModels\Interfaces\Redactable;
use Illuminate\Contracts\Database\Eloquent\Builder;

class User extends Model implements Redactable
{
    // ...

    public function redactable(): Builder
    {
        return static::query()->where('created_at', 'redactFields();
```

By default, this will redact the fields using the strategy defined in the model's `redactionStrategy` method.

You can override this by passing a custom redaction strategy to the `redactFields` method like so:

```
use App\Models\User;
use AshAllenDesign\RedactableModels\Support\Strategies\ReplaceContents;

$user = User::find(1);

$user->redactFields(
    strategy: app(ReplaceContents::class)->replaceWith(['name' => 'REDACTED'])
);
```

### Events

[](#events)

#### `ModelRedacted`

[](#modelredacted)

When a model is redacted, an `AshAllenDesign\RedactableModels\Events\ModelRedacted` event is fired that can be listened on.

Please note, this event is not fired if the model was mass redacted (i.e., the model uses the `AshAllenDesign\RedactableModels\Interfaces\MassRedactable` interface). This is because the models are never actually retrieved from the database when mass redacting, so there isn't a model instance to pass to the event.

Testing
-------

[](#testing)

To run the package's unit tests, run the following command:

```
vendor/bin/phpunit
```

Security
--------

[](#security)

If you find any security related issues, please contact me directly at  to report it.

Contribution
------------

[](#contribution)

If you wish to make any changes or improvements to the package, feel free to make a pull request.

Note: A contribution guide will be added soon.

Credits
-------

[](#credits)

- [Ash Allen](https://ashallendesign.co.uk)
- [Jess Allen](https://jesspickup.co.uk) (Logo)
- [All Contributors](https://github.com/ash-jc-allen/redactable-models/graphs/contributors)

Changelog
---------

[](#changelog)

Check the [CHANGELOG](CHANGELOG.md) to get more information about the latest changes.

License
-------

[](#license)

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

Support Me
----------

[](#support-me)

If you've found this package useful, please consider buying a copy of [Battle Ready Laravel](https://battle-ready-laravel.com) to support me and my work.

Every sale makes a huge difference to me and allows me to spend more time working on open-source projects and tutorials.

To say a huge thanks, you can use the code **BATTLE20** to get a 20% discount on the book.

[👉 Get Your Copy!](https://battle-ready-laravel.com)

[![Battle Ready Laravel](https://camo.githubusercontent.com/20876b9d7d30882812a8e9da128da0966cc0b72473fb9ed6b2941294475bbcb0/68747470733a2f2f617368616c6c656e64657369676e2e636f2e756b2f696d616765732f637573746f6d2f73706f6e736f72732f626174746c652d72656164792d6c61726176656c2d686f72697a6f6e74616c2d62616e6e65722e706e67)](https://battle-ready-laravel.com)

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance87

Actively maintained with recent releases

Popularity37

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 88.6% 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 ~119 days

Recently: every ~50 days

Total

6

Last Release

62d ago

Major Versions

v0.1.0 → v1.0.02025-08-29

PHP version history (2 changes)v0.1.0PHP ^8.2

v1.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/b3920670b9243211cc80d219d943d782bd3ecae81b81c524e03538c0f094f392?d=identicon)[ashallendesign](/maintainers/ashallendesign)

---

Top Contributors

[![ash-jc-allen](https://avatars.githubusercontent.com/u/39652331?v=4)](https://github.com/ash-jc-allen "ash-jc-allen (78 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (7 commits)")[![messikiller](https://avatars.githubusercontent.com/u/10354220?v=4)](https://github.com/messikiller "messikiller (2 commits)")[![JonPurvis](https://avatars.githubusercontent.com/u/7534029?v=4)](https://github.com/JonPurvis "JonPurvis (1 commits)")

---

Tags

laravelmodelsashallendesignredactable-models

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

### Embed Badge

![Health badge](/badges/ashallendesign-redactable-models/health.svg)

```
[![Health](https://phpackages.com/badges/ashallendesign-redactable-models/health.svg)](https://phpackages.com/packages/ashallendesign-redactable-models)
```

###  Alternatives

[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4205.3M84](/packages/livewire-volt)[gehrisandro/tailwind-merge-laravel

TailwindMerge for Laravel merges multiple Tailwind CSS classes by automatically resolving conflicts between them

341682.2k18](/packages/gehrisandro-tailwind-merge-laravel)[whitecube/laravel-timezones

Store UTC dates in the database and work with custom timezones in the application.

106106.2k](/packages/whitecube-laravel-timezones)[ashallendesign/laravel-executor

Configurable code that can be ran when installing or updating your web app.

2573.0k](/packages/ashallendesign-laravel-executor)[forxer/laravel-gravatar

A library providing easy gravatar integration in a Laravel project.

4235.6k](/packages/forxer-laravel-gravatar)[vildanbina/laravel-versions

A Laravel package for managing model drafts.

333.3k](/packages/vildanbina-laravel-versions)

PHPackages © 2026

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