https://github.com/kielabokkie/laravel-conceal
Conceal data in an array or collection
https://github.com/kielabokkie/laravel-conceal
composer-package conceal-data laravel laravel-package security sensitive-data
Last synced: 3 months ago
JSON representation
Conceal data in an array or collection
- Host: GitHub
- URL: https://github.com/kielabokkie/laravel-conceal
- Owner: kielabokkie
- License: mit
- Created: 2020-01-25T22:39:47.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-01-05T21:01:59.000Z (over 3 years ago)
- Last Synced: 2025-03-01T08:12:19.356Z (3 months ago)
- Topics: composer-package, conceal-data, laravel, laravel-package, security, sensitive-data
- Language: PHP
- Homepage:
- Size: 33.2 KB
- Stars: 23
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel Conceal
[](https://twitter.com/kielabokkie)
[](https://github.com/kielabokkie/laravel-conceal/actions)
[](https://packagist.org/packages/kielabokkie/laravel-conceal)
[](LICENSE.md)This package allows you to conceal sensitive data in arrays and collections. This is particularly useful when writing possibly sensitive data to log files.
Once installed you can do things like this:
```php
$data = [
'username' => 'wouter',
'api_key' => 'secret'
];$hide = ['api_key'];
$output = conceal($data, $hide);
print_r($output);// Outputs: ['username' => 'wouter', 'api_key' => '********']
```## Requirements
* PHP >= 7.2
* Laravel 5.7+ | 6 | 7 | 8## Installation
Install the package via composer:
```
composer require kielabokkie/laravel-conceal
```## Package configuration
This package has minimal configuration. All you can do at the moment is set the keys that are concealed by default. If you want to add your own defaults you can do that by publishing the config file by running the following command:
```bash
php artisan vendor:publish --provider="Kielabokkie\LaravelConceal\ConcealServiceProvider"
```These are the contents of the file that will be published at `config/conceal.php`:
```php
return [
/*
* Array of keys that will be concealed automatically.
*/
'defaults' => [
'password',
'password_confirmation',
]
];
```## Usage
Use the default configuration to conceal the password:
```php
$data = [
'username' => 'wouter',
'password' => 'secret'
];$output = conceal($data);
print_r($output);// Outputs: ['username' => 'wouter', 'password' => '********']
```Set keys on the fly:
```php
$data = [
'api_key' => 'secret'
];$output = conceal($data, ['api_key']);
print_r($output);// Outputs: ['api_key' => '********']
```Everything works exactly the same for collections:
```php
$data = new Collection([
'username' => 'wouter',
'password' => 'secret'
]);$output = conceal($data);
print_r($output->toArray());// Outputs: ['username' => 'wouter', 'password' => '********']
```And last but not least, it works recursively too:
```php
$data = [
'password' => 'secret',
'nextlevel' => [
'password' => 'secret',
]
];$output = conceal($data);
print_r($output);// Outputs: ['password' => '********', 'nextlevel' => ['password' => '********']]
```### Facade
The examples above use the `conceal()` helper function. If Facades are more your thing you can use that instead:
```php
use Kielabokkie\LaravelConceal\Facades\Concealer;$data = [
'password' => 'secret'
];$output = Concealer::conceal($data);
print_r($output);// Outputs: ['password' => '********']
```