PHPackages                             eloquent-works/masquerade - 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. eloquent-works/masquerade

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

eloquent-works/masquerade
=========================

A feature-rich Laravel impersonation package with secure session handling, audit logs, middleware, events, and Blade helpers.

v1.0.0(yesterday)10MITPHP ^8.2

Since Jul 19Compare

[ Source](https://github.com/EloquentWorks/Masquerade)[ Packagist](https://packagist.org/packages/eloquent-works/masquerade)[ RSS](/packages/eloquent-works-masquerade/feed)WikiDiscussions Synced today

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

🎭 Laravel Masquerade
====================

[](#-laravel-masquerade)

[![Tests](https://github.com/EloquentWorks/Masquerade/actions/workflows/tests.yml/badge.svg)](https://github.com/EloquentWorks/Masquerade/actions/workflows/tests.yml)[![Latest Release](https://camo.githubusercontent.com/761aaea489d5e1d9963a49bc8d1f5f74da52e512b96cc930aca6591a1cf678d6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f456c6f7175656e74576f726b732f4d617371756572616465)](https://github.com/EloquentWorks/Masquerade/releases)[![License](https://camo.githubusercontent.com/daf6a0e7894e1fd79c863bc968f8c6235adcefd5dcd76d1966d24d2832050c93/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f456c6f7175656e74576f726b732f4d617371756572616465)](LICENSE.md)

A feature-rich user impersonation package for Laravel.

Laravel Masquerade lets trusted administrators, support agents, and staff safely sign in as another user while preserving the original account, enforcing permission checks, blocking sensitive actions, limiting impersonation duration, and recording a full audit trail.

```
use EloquentWorks\Masquerade\Facades\Masquerade;

Masquerade::start(
    target: $user,
    reason: 'Troubleshooting support ticket #1042',
    metadata: [
        'ticket_id' => 1042,
    ],
);

Masquerade::isMasquerading();

Masquerade::stop();
```

✨ Highlights
------------

[](#-highlights)

- Secure session-backed user impersonation
- Original user restoration after masquerade sessions
- Configurable auth guard support
- Configurable user model for built-in routes
- Optional built-in start and stop routes
- Controller-driven impersonation flow
- Model-level permission methods
- Protection against nested impersonation
- Protection against impersonating yourself
- Optional required reason before starting a session
- Session ID regeneration when starting and stopping
- Configurable max session duration
- Automatic expiration middleware
- Sensitive-route blocking middleware
- Middleware for routes that require an active masquerade session
- Full audit logging with actor and target morph relationships
- Reason, IP address, user agent, metadata, start time, and end time logging
- Start, stop, denied, and expired events
- Blade conditional directive and banner directive
- Publishable banner view
- Facade and global helper
- Install and log pruning Artisan commands
- Configurable table name, messages, redirects, and routes
- Laravel Pint, PHPStan/Larastan, PHPUnit, Testbench, and GitHub Actions setup

📋 Requirements
--------------

[](#-requirements)

LaravelPHPOrchestra Testbench11.15+8.2+9.x12.x8.2+10.x13.x8.3+11.x📦 Installation
--------------

[](#-installation)

```
composer require eloquent-works/masquerade
php artisan masquerade:install
php artisan migrate
```

The install command publishes the configuration file, migration, and banner view.

Publish only the configuration file:

```
php artisan vendor:publish --tag=masquerade-config
```

Publish only the migration:

```
php artisan vendor:publish --tag=masquerade-migrations
```

Publish only the banner view:

```
php artisan vendor:publish --tag=masquerade-views
```

Force republishing package assets:

```
php artisan masquerade:install --force
```

👤 Prepare Your User Model
-------------------------

[](#-prepare-your-user-model)

Add `HasMasquerade` to the account model that can perform or receive impersonation.

```
