tchilly/email-masking
最新稳定版本:v0.0.2
Composer 安装命令:
composer require tchilly/email-masking
包简介
A Laravel package for masking email addresses
README 文档
README
This package provides a simple way to mask email addresses in your Laravel applications.
Installation
composer require Tchilly/EmailMasking
Usage
In your models
<?php namespace App\Models; use Illuminate\Foundation\Auth\User as Authenticatable; use Tchilly\EmailMasking\Traits\HasMaskedEmail; class User extends Authenticatable { use HasMaskedEmail; // Make sure to add 'email_masked' to your $appends array // if you want it included in your model's array/JSON form protected $appends = ['email_masked']; }
Then you can access the masked email as a property:
$user = User::first(); echo $user->email_masked; // j***@example.com
You can also use the method with custom options:
$user = User::first(); echo $user->getMaskedEmail(); // Default masking (same as email_masked) echo $user->getMaskedEmail(null, 3); // With max 3 asterisks echo $user->getMaskedEmail('custom@example.com'); // Custom email with default masking
As a utility function
You can also use the trait's static method directly:
use Tchilly\EmailMasking\Traits\HasMaskedEmail; $maskedEmail = HasMaskedEmail::maskEmail('john.doe@example.com'); echo $maskedEmail; // j******@example.com // Customize the maximum number of asterisks $maskedEmail = HasMaskedEmail::maskEmail('john.doe@example.com', 3); echo $maskedEmail; // j***@example.com
Configuration
You can customize the default masking behavior by overriding the emailMasked method in your model:
// In your model protected function emailMasked(): Attribute { return new Attribute( get: fn () => static::maskEmail($this->email, 3) // Always use max 3 asterisks ); }
Author
Magnus Vike magnus@vike.se
License
This package is open-sourced software licensed under the MIT license.
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-05