PHPackages                             irabbi360/laravel-attribute-mask - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. irabbi360/laravel-attribute-mask

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

irabbi360/laravel-attribute-mask
================================

Mask Eloquent attributes on retrieval like $casts

v1.0.0(5mo ago)301.1k↑226.7%MITPHPPHP ^8.1 | ^8.2 | ^8.3 | ^8.4

Since Jan 25Pushed 5mo agoCompare

[ Source](https://github.com/irabbi360/laravel-attribute-mask)[ Packagist](https://packagist.org/packages/irabbi360/laravel-attribute-mask)[ Docs](https://github.com/irabbi360/laravel-attribute-mask)[ RSS](/packages/irabbi360-laravel-attribute-mask/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (1)Dependencies (8)Versions (2)Used By (0)

Mask Eloquent Attributes on Retrieval
=====================================

[](#mask-eloquent-attributes-on-retrieval)

[![Latest Version on Packagist](https://camo.githubusercontent.com/fa8b59ff116aba8246929957176477120e320b49abca1ce7502edee9e58a9b14/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6972616262693336302f6c61726176656c2d6174747269627574652d6d61736b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/irabbi360/laravel-attribute-mask)[![GitHub Tests Action Status](https://camo.githubusercontent.com/717016596b925fd0e235aee28da55cd1399081df69df66b5526accfbe6fcc483/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6972616262693336302f6c61726176656c2d6174747269627574652d6d61736b2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/irabbi360/laravel-attribute-mask/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/ad5380a9ba8f7eb60691458019d470eb889b40dcc78cd714987d694da69b21a3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6972616262693336302f6c61726176656c2d6174747269627574652d6d61736b2f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/irabbi360/laravel-attribute-mask/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/df97d5a162f404170cc4435691681f29d7b2df648d8aa0f8c36ec102a1df9215/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6972616262693336302f6c61726176656c2d6174747269627574652d6d61736b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/irabbi360/laravel-attribute-mask)

A Laravel package that automatically masks sensitive model attributes on retrieval. Supports email, phone, and text masking with highly configurable rules.

Features
--------

[](#features)

- Automatic attribute masking on retrieval
- Email, phone, and text masking support
- Configurable mask character and visibility
- Global or per-attribute masking rules
- Auto-detection of phone fields by column name

Installation
------------

[](#installation)

```
composer require irabbi360/laravel-attribute-mask
```

Publish the config file:

```
php artisan vendor:publish --tag="attribute-mask-config"
```

Configuration
-------------

[](#configuration)

The default configuration (`config/attribute-mask.php`):

```
return [
    'enabled' => true,
    'mask_char' => '*',

    'email_masking' => [
        'show_domain' => true,
        'show_start' => 1,
        'show_end' => 1,
    ],

    'phone_masking' => [
        'show_start' => 3,
        'show_end' => 2,
        'patterns' => ['phone', 'phone_number', 'mobile', 'mobile_number', ...],
    ],

    'text_masking' => [
        'show_start' => 3,
        'show_end' => 3,
    ],
];
```

Usage
-----

[](#usage)

### Define Maskable Attributes

[](#define-maskable-attributes)

Add the `HasMaskedAttributes` trait and define maskable attributes using the `maskables()` method:

```
use Irabbi360\LaravelAttributeMask\Concern\HasMaskedAttributes;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use HasMaskedAttributes;

    /**
     * Get the attributes that should be masked.
     */
    protected function maskables(): array
    {
        return ['email', 'phone', 'phone_number', 'ssn'];
    }
}
```

Alternatively, use the `$maskable` property:

```
class User extends Model
{
    use HasMaskedAttributes;

    protected array $maskable = ['email', 'phone', 'ssn'];
}
```

### Masking Behavior

[](#masking-behavior)

Attributes are automatically masked on retrieval:

```
$user = User::find(1);

$user->email;       // t**t@example.com
$user->phone;       // 123****90
$user->ssn;         // 123***789
```

### Retrieving Original Values

[](#retrieving-original-values)

Get the unmasked value using `getOriginal()`:

```
$user->getOriginal('email');  // test@example.com
```

Or temporarily disable masking:

```
config(['attribute-mask.enabled' => false]);
$original = $user->email;
config(['attribute-mask.enabled' => true]);
```

### Email Masking

[](#email-masking)

Configure email masking behavior:

```
'email_masking' => [
    'show_domain' => true,      // Show domain part
    'show_start' => 2,          // Show first 2 characters
    'show_end' => 2,            // Show last 2 characters
],
```

Examples:

- `test@example.com` → `te**t@example.com`
- `john.doe@example.com` → `jo**oe@example.com`

### Phone Masking

[](#phone-masking)

Phone fields are auto-detected by column name. Configure visibility:

```
'phone_masking' => [
    'show_start' => 3,
    'show_end' => 2,
],
```

Examples:

- `1234567890` → `123****90`
- `+1-555-123-4567` → `+15-***-67`

Add custom phone patterns:

```
'phone_masking' => [
    'patterns' => ['phone', 'mobile', 'whatsapp', 'fax'],
],
```

### Text Masking

[](#text-masking)

For other text attributes:

```
'text_masking' => [
    'show_start' => 3,
    'show_end' => 3,
],
```

Examples:

- `secretpassword` → `sec********rd`
- `API_KEY_12345` → `API***345`

### Custom Mask Character

[](#custom-mask-character)

Change the mask character globally:

```
'mask_char' => '#',

// Result: test@example.com → t##t@example.com
```

### Disable Masking

[](#disable-masking)

Disable globally:

```
'enabled' => false,
```

Or temporarily:

```
config(['attribute-mask.enabled' => false]);
$user->email;  // Returns unmasked value
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for details on updates.

Contributing
------------

[](#contributing)

See [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines.

Security
--------

[](#security)

Report security vulnerabilities via [Security Policy](../../security/policy).

Credits
-------

[](#credits)

- [Fazle Rabbi](https://github.com/irabbi360)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License. See [LICENSE.md](LICENSE.md) for details.

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance72

Regular maintenance activity

Popularity29

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

160d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3550a7f53f819e536401ac2a5357c930d6316a6c129f65b220332b0d0b42ad87?d=identicon)[irabbi360](/maintainers/irabbi360)

---

Top Contributors

[![irabbi360](https://avatars.githubusercontent.com/u/35403788?v=4)](https://github.com/irabbi360 "irabbi360 (6 commits)")

---

Tags

laravelirabbi360laravel-attribute-mask

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/irabbi360-laravel-attribute-mask/health.svg)

```
[![Health](https://phpackages.com/badges/irabbi360-laravel-attribute-mask/health.svg)](https://phpackages.com/packages/irabbi360-laravel-attribute-mask)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

329530.5k29](/packages/codewithdennis-filament-select-tree)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

124603.0k](/packages/worksome-exchange)[tarfin-labs/event-machine

Event-driven state machines for Laravel with event sourcing, type-safe context, and full audit trail.

199.4k](/packages/tarfin-labs-event-machine)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
