PHP code example of dialect / laravel-gdpr-compliance
1. Go to this page and download the library: Download dialect/laravel-gdpr-compliance 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/ */
dialect / laravel-gdpr-compliance example snippets
namespace App;
use Dialect\Gdpr\Anonymizable;
class User extends Model
{
use Anonymizable;
protected $gdprAnonymizableFields = [
'email'
];
/**
* Using getAnonymized{column} to return anonymizable data
*/
public function getAnonymizedEmail()
{
return random_bytes(10);
}
}
class Order extends Model
{
use Anonymizable;
protected $guarded = [];
protected $table = 'orders';
protected $gdprWith = ['product'];
protected $gdprAnonymizableFields = ['buyer' => 'Anonymized Buyer'];
public function product()
{
return $this->belongsTo(Product::class);
}
public function customer()
{
return $this->belongsTo(Customer::class);
}
}
class Customer extends Model
{
use Anonymizable;
protected $guarded = [];
protected $table = 'customers';
protected $gdprWith = ['orders'];
protected $gdprAnonymizableFields = ['name' => 'Anonymized User'];
public function orders()
{
return $this->hasMany(Order::class);
}
}
use Dialect\Gdpr\Portable;
class User extends Model
{
use Portable;
/**
* Get the GDPR compliant data portability array for the model.
*
* @return array
*/
public function toPortableArray()
{
$array = $this->toArray();
// Customize array...
return $array;
}
}
use Dialect\Gdpr\Portable;
class User extends Model
{
use Portable;
/**
* The relations to
use Dialect\Gdpr\Portable;
class User extends Model
{
use Portable;
/**
* The attributes that should be hidden for the downloadable data.
*
* @var array
*/
protected $gdprHidden = ['password'];
}
use Dialect\Gdpr\Portable;
class User extends Moeld
{
use Portable;
/**
* The attributes that should be visible in the downloadable data.
*
* @var array
*/
protected $gdprVisible = ['name', 'email'];
}
use Dialect\Gdpr\EncryptsAttributes;
class User extends Model
{
use EncryptsAttributes;
/**
* The attributes that should be encrypted and decrypted on the fly.
*
* @var array
*/
protected $encrypted = ['ssnumber'];
}