Download the PHP package bernskiold/laravel-data-scrubber without Composer

On this page you can find all versions of the php package bernskiold/laravel-data-scrubber. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-data-scrubber

Laravel Data Scrubber

Latest Version on Packagist GitHub Tests Action Status Total Downloads

A Laravel package for scrubbing PII (Personally Identifiable Information) and sensitive data from Eloquent models. Useful for GDPR compliance and data retention policies.

Installation

Install the package via composer:

Optionally publish the configuration file:

If you're using Laravel Horizon, add the data-scrubber queue to your config/horizon.php:

Usage

Implementing Scrubbable on a Model

To make a model scrubbable, implement the Scrubbable interface and use the ScrubsData trait:

Available Scrubbing Strategies

Strategy Description Example Result
NullStrategy Sets the value to null null
RedactedStrategy Replaces with [REDACTED] [REDACTED]
AnonymizeFirstNameStrategy Replaces with "Deleted" Deleted
AnonymizeLastNameStrategy Replaces with "User" User
AnonymizeEmailStrategy Replaces with a generic email [email protected]
AnonymizeEmailWithIdStrategy Replaces with email containing model ID [email protected]
HashStrategy Hashes the value (SHA-256 by default, salted) a8f5f167f44f4964e6c998dee827110c...
DeleteFileStrategy Deletes file from storage and sets to null null
MaskStrategy Masks middle characters, showing start and end 12******90
TruncateStrategy Keeps first N characters and adds suffix Jon***
IpAnonymizeStrategy Zeros out trailing IPv4/IPv6 octets (GDPR) 192.168.0.0
JsonFieldStrategy Scrubs specific keys in JSON/array data (varies per key)
ConditionalStrategy Applies different strategies based on conditions (depends on condition)
CallbackStrategy Uses a custom closure handler (depends on handler)

Hashing note: An unsalted hash of low-cardinality data (emails, phone numbers) can be reversed with brute-force or rainbow tables. Set a secret in data-scrubber.strategies.hash.salt (e.g. env('DATA_SCRUBBER_HASH_SALT')) to switch HashStrategy to HMAC and make the result non-reversible. Note that changing the algorithm or salt changes the output, so apply it before scrubbing.

Using Strategy Classes Directly

For more control, you can instantiate strategy classes directly with custom parameters:

Using Custom Callbacks

For more complex scrubbing logic, use the CallbackStrategy:

You can also use the fluent builder pattern:

Timestamp Logging

By default, the package logs when a record was scrubbed by updating a scrubbed_at column. This allows you to:

Add the column to your migration using the provided Blueprint macro:

This creates a nullable timestamp column using the name from your config (data-scrubber.timestamp_column, defaults to scrubbed_at).

To customize timestamp logging behavior, override getScrubOptions() in your model:

To use a different column name:

Query Scopes

When timestamp logging is enabled, the trait provides query scopes:

Scrubbing Individual Records

You can scrub a single record programmatically:

Artisan Commands

The package provides two artisan commands for managing data scrubbing.

Scrub Command

Run the scrubber to process all eligible records:

By default, scrubbing is performed asynchronously using Laravel's queue system. You can configure this behavior globally in the config file or per-model via getScrubOptions().

Config Report Command

View the configuration of all Scrubbable models:

This command displays a summary of all configured models, their fields, scrubbing strategies, and processing options.

Configuration

The configuration file allows you to customize the package behavior:

Publishing a partial config: Laravel merges a published config with the package defaults at the top level only. If you publish config/data-scrubber.php and keep only some keys under a nested array (such as strategies or queue), the unspecified sub-keys fall back to their hard-coded strategy defaults rather than being merged. Keep the full nested arrays in your published file to avoid surprises.

How records are processed

When scrubbing asynchronously, each queued job scrubs a single chunk (chunk_size) of records and, if more remain, dispatches a follow-up job for the next chunk. This keeps individual jobs small on large tables and makes retries safe — a failed job only re-processes its own chunk.

The command and jobs only ever operate on records returned by your scrubbableQuery(), further narrowed to those that have not already been scrubbed (when timestamp logging is enabled). This guards non-idempotent strategies such as HashStrategy against being applied twice on retries or repeated runs.

You can override options on a per-model basis by implementing getScrubOptions() in your model:

Events

When a model is scrubbed, the package dispatches a Scrubbed event. You can register listeners for this event to perform additional actions such as notifying external systems, clearing caches, or triggering other workflows.

Activity Log Integration (Optional)

If you have Spatie Activity Log installed, the package provides two optional listeners for different purposes.

Logging Scrub Activity

To log when records are scrubbed, register the LogScrubbedActivity listener in your EventServiceProvider:

This listener will:

You can customize the event name and description in your config:

Scrubbing Activity Log Entries

Activity logs often store PII in their properties JSON column (e.g., old/new attribute values). To automatically scrub this data when a model is scrubbed, register the ScrubActivityLogListener:

This listener will scrub the configured property keys (default: old and attributes) in all activity log entries for the scrubbed model, using the same strategies defined in scrubbableFields().

You can customize which property keys are scrubbed in your config:

To customize the behavior per-model, implement the ScrubsActivityLog interface:

Testing

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Credits

License

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


All versions of laravel-data-scrubber with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/contracts Version ^11.0|^12.0|^13.0
laravel/prompts Version ^0.1.18|^0.2.0|^0.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package bernskiold/laravel-data-scrubber contains the following files

Loading the files please wait ...