PHP code example of langleyfoxall / laravel-redacted-model

1. Go to this page and download the library: Download langleyfoxall/laravel-redacted-model library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

langleyfoxall / laravel-redacted-model example snippets


class SensitiveModel extends RedactedModel
{
	protected $redacted = ['name'];
}

class SensitiveModel extends RedactedModel
{
	protected $redacted = ['name'];
	
	public function shouldRedactField($key)
	{
		return !\Auth::user()->canSeeSensitiveFields();
	}
}

class SensitiveModel extends RedactedModel
{
	protected $redacted = ['name'];
	
	protected $redactedString = '[Top Secret]';
}

class SensitiveModel extends RedactedModel
{
	protected $redacted = ['name'];
	
	protected $redact = false;
}

class SensitiveModel extends RedactedModel
{
	protected $redacted = ['name'];
	
	protected $redactKeys = false;
}

class SensitiveModel extends RedactedModel
{
	protected $redacted = ['name'];
	
	public function getNameRedactedValue($value)
	{
		return subStr($value, 0, 1).'***'.subStr($value, -1 ,1);
	}
	
}

...

$instanceOfRedactedModel->name // Returns K***y instead of Kathryn Janeway

class SensitiveModel extends RedactedModel
{
	protected $redacted = ['name'];
	
	public function defaultRedactedValue($key, $value)
	{
		return str_repeat("*", strlen($value)); 
	}
}

...

$instanceOfRedactedModel->name // Returns ********** instead of Section 31


class SensitiveModel extends RedactedModel
{
	protected $redacted = ['name'];
}

...

$instanceOfRedactedModel->name // Returns [Hidden Data]

$instanceOfRedactedModel->disableProtection();

$instanceOfRedactedModel->name // Returns Reginald Barclay