mozhuilungdsuo/universal-mask
最新稳定版本:v1.0.0
Composer 安装命令:
composer require mozhuilungdsuo/universal-mask
包简介
A flexible Laravel masking utility for names, IDs, and phone numbers.
README 文档
README
A flexible, lightweight Laravel package to mask sensitive data like Names, Government IDs (Aadhaar, PAN), Phone numbers, and DOBs while keeping specific characters visible at the start and end.
Installation
You can install the package via Composer:
composer require mozhuilungdsuo/universal-mask
Features
- Dynamic Blade Directive: Use
@u_maskdirectly in your views with custom parameters. - Global Helper Function: Access
u_mask()in Controllers, Models, or API Resources. - Multi-word Support: Automatically detects spaces and masks each part of a full name individually (e.g., "John Doe" becomes "J**n D*e").
- UTF-8 Support: Uses Laravel's
Strhelpers to safely handle special characters and accents.
Usage
1. In Blade Views
The directive allows you to specify how many characters to reveal at the start and end, and optionally change the mask character.
Syntax: @u_mask($value, $showStart, $showEnd, $maskChar)
| Data Type | Blade Directive | Input | Output |
|---|---|---|---|
| Standard Name | @u_mask($name, 1, 1) |
Alexander |
A*******r |
| Aadhaar / ID | @u_mask($uid, 0, 4) |
555566667777 |
********7777 |
| Phone Number | @u_mask($phone, 2, 2) |
9876543210 |
98******10 |
| Custom Char | @u_mask($name, 1, 1, 'x') |
John |
Jxxn |
2. In PHP / Controllers
Use the helper function for API responses or backend logic:
// Basic usage $masked = u_mask('John Harrison', 1, 2); // Result: J*hn H******on // Masking a phone number in a Controller $phone = u_mask($user->phone, 0, 3); // Result: *******210
Parameters Reference
The u_mask function and directive accept the following arguments:
$value(string|null): The string you want to mask.$showStart(int): Number of characters to remain visible at the beginning. (Default:1)$showEnd(int): Number of characters to remain visible at the end. (Default:1)$char(string): The character used for masking. (Default:*)
Note: To prevent data corruption, if the total length of the string is less than or equal to the sum of
$showStart+$showEnd, the package will return the original string unmasked.
Requirements
- PHP: ^8.1
- Laravel: ^10.0, ^11.0, or ^12.0
统计信息
- 总下载量: 16
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-10