PHP code example of alvarofpp / masks

1. Go to this page and download the library: Download alvarofpp/masks 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/ */

    

alvarofpp / masks example snippets



$cpf = '12345678901';
$mask = '###.###.###-##';

echo mask($mask, $cpf);
// Result: 123.456.789-01



namespace App;

use Alvarofpp\Masks\Traits\MaskAttributes;
// ...

class User extends Authenticatable
{
    use MaskAttributes;

    /**
     * The attributes that should be masked.
     *
     * @var array
     */
    protected $masks = [
        'cpf' => '###.###.###-##',
        'phone' => [
            10 => '(##) ####-####',
            11 => '(##) ###-###-###',
        ],
    ];
    // ...
}



namespace App;

use Alvarofpp\Masks\Traits\MaskAttributes;
// ...

class User extends Authenticatable
{
    use MaskAttributes;

    /**
     * Indicates the suffix of masked attributes.
     * 
     * @var string 
     */
    protected $maskSuffix = '_formatted';

    /**
     * The attributes that should be masked.
     *
     * @var array
     */
    protected $masks = [
        'cpf' => '###.###.###-##',
    ];
    // ...
}