Created
November 2, 2022 06:51
-
-
Save shibbirweb/56d879a6020fea2409b9bfd82941204f to your computer and use it in GitHub Desktop.
Laravel Secure Helper Trait
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Models\Traits\ModelHelpers; | |
use Illuminate\Support\Str; | |
trait SecureHelperTrait | |
{ | |
/** | |
* Mask user secret data. | |
* | |
* @param string $phone | |
* @param int $skip_start | |
* @param int $skip_end | |
* @return string | |
*/ | |
protected function maskUserSecretData(string $text, int $skip_start = 3, int $skip_end = 3) | |
{ | |
$total_length = strlen($text); | |
$end_index = $total_length - ($skip_start + $skip_end); | |
$string = Str::mask($text, '*', - ($total_length - $skip_start), $end_index); | |
return substr_replace($string, '****', $skip_start, $end_index); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment