damiankulon/laravel-model-masker

GDPR friendly database masker for Laravel

dev-master 2020-01-06 23:21 UTC

This package is auto-updated.

Last update: 2025-05-20 01:08:46 UTC


README

This package is a small PHP library for masking sensitive data. You can configure various masking strategies just add to the config file.

Installation

Require this package with composer.

composer require damiankulon/laravel-model-masker

Copy the package config to your local config with the publish command:

php artisan vendor:publish --provider="LaravelModelMasker\ServiceProvider"

Example config file fur tables

'tables' => [
        \App\User::class    => [
            'name'       => [
                'maskStrategy' => 'starify',
            ],
            'password'   => null, // no action 
            'email'      => [
                'maskStrategy' => 'hashify',
                'options'      => [
                    'template' => "%s@example.com"
                ]
            ]
        ]
]

Laravel 5.7+:

If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php

LaravelModelMasker\ServiceProvider::class,

If you want to use the facade to mask models, add this to your facades in app.php:

'ModelMasker' => LaravelModelMasker\Facade::class,

Usage

$user = User::first();
$masker = new ModelMasker();
$masker->mask($user)->save(); // Mask model attributes and save model

\ModelMasker::mask($user)->save(); // use Facade