定制 mozhuilungdsuo/universal-mask 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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_mask directly 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 Str helpers 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:

  1. $value (string|null): The string you want to mask.
  2. $showStart (int): Number of characters to remain visible at the beginning. (Default: 1)
  3. $showEnd (int): Number of characters to remain visible at the end. (Default: 1)
  4. $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

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固