"Str::mask()" method

Laravel 8.69 released with "Str::mask()" method which masks a portion of string with a repeated character

1class PasswordResetLinkController extends Controller
2{
3 public function sendResetLinkResponse(Request $request)
4 {
5 $userEmail = User::where('email', $request->email)->value('email'); // username@domain.com
6 
7 $maskedEmail = Str::mask($userEmail, '*', 4); // user***************
8 
9 // If needed, you provide a negative number as the third argument to the mask method,
10 // which will instruct the method to begin masking at the given distance from the end of the string
11 
12 $maskedEmail = Str::mask($userEmail, '*', -16, 6); // use******domain.com
13 }
14}

Tip given by @Teacoders

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord