PHPackages                             chadhurin/laravel-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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. chadhurin/laravel-masquerade

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

chadhurin/laravel-masquerade
============================

Elevate your user management experience with the powerful Laravel Masquerade Package. Designed for seamless integration with Laravel applications, this package empowers administrators to temporarily switch and view the application through the eyes of another user. Whether you're debugging, testing user experiences, or verifying permissions, our Masquerade Package streamlines the process.

v1.0.0(2y ago)1524↓75%MITPHPPHP ^8.0

Since Sep 1Pushed 2y ago1 watchersCompare

[ Source](https://github.com/chadhurin/laravel-masquerade)[ Packagist](https://packagist.org/packages/chadhurin/laravel-masquerade)[ Docs](https://github.com/chadhurin/laravel-masquerade)[ RSS](/packages/chadhurin-laravel-masquerade/feed)WikiDiscussions main Synced 1mo ago

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

Laravel Masquerade
==================

[](#laravel-masquerade)

[![Latest Version on Packagist](https://camo.githubusercontent.com/20ef7d25baa9c1f51545e9b8ca968ba2eb9437fb431acf81fd799ca43e5a42d9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63686164687572696e2f6c61726176656c2d6d6173717565726164652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chadhurin/laravel-masquerade)[![Total Downloads](https://camo.githubusercontent.com/2bd067e7ebcd840102eff35472bddd8c27a53abf4e3eaa21f3c75b4a5be8b639/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63686164687572696e2f6c61726176656c2d6d6173717565726164652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chadhurin/laravel-masquerade)

Elevate your user management experience with the powerful Laravel Masquerade Package. Designed for seamless integration with Laravel applications, this package empowers administrators to temporarily switch and view the application through the eyes of another user. Whether you're debugging, testing user experiences, or verifying permissions, our Masquerade Package streamlines the process.

Key Features
------------

[](#key-features)

- **Effortless User Switching:** Quickly and securely switch to any user account within your application.
- **Realistic User Experience:** Gain insights by experiencing the application exactly as the selected user would.
- **Advanced Permissions Testing:** Verify and troubleshoot user permissions with ease.
- **Developer-Friendly:** Intuitive setup and configuration for smooth integration into your existing Laravel project.

Inspiration
-----------

[](#inspiration)

This package was inspired by the fantastic work done in the [laravel-impersonate](https://github.com/404labfr/laravel-impersonate) package. We recognized the value it brought to the community and aimed to build upon its ideas while adding our unique features particularly with Laravel Sanctum support. We needed to quickly add support for Sanctum so a few other features were left out. We hope to add them in the future.

Requirements
------------

[](#requirements)

- Laravel 10.x
- PHP &gt;= 8.0

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

[](#installation)

You can install the package via composer:

```
composer require chadhurin/laravel-masquerade
```

Then, add the trait `Chadhurin\LaravelMasquerade\Traits\Masquerade` to your **User** model.

Usage
=====

[](#usage)

Simple usage
------------

[](#simple-usage)

Masquerade a user:

```
Auth::user()->masquerade($other_user);
// You're now logged as the $other_user
```

Leave a Masquerade:

```
Auth::user()->leaveMasquerade();
// You're now logged as your original user.
```

### Using the built-in controller

[](#using-the-built-in-controller)

In your routes file, under web middleware, you must call the `masquerade` route macro.

```
Route::masquerade();
```

Advanced Usage
--------------

[](#advanced-usage)

### Defining masquerade authorization

[](#defining-masquerade-authorization)

By default all users can **masquerade** an user.
You need to add the method `canMasquerade()` to your user model:

```
    /**
     * @return bool
     */
    public function canMasquerade(): bool
    {
        return $this->hasRole('super-admin');
        // For example, you can check if the user has a specific role.
    }
```

By default all users can **be masqueraded**.
You need to add the method `canBeMasqueraded()` to your user model to extend this behavior:

```
    /**
     * @return bool
     */
     public function canBeMasqueraded():bool
    {
        return !$this->hasRole('super-admin')
        && $this->can_be_masqueraded;
        // For example, you can check if the user has a specific role and if the user has a flag on the users table
    }
```

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

[](#configuration)

The package comes with a configuration file.

Publish it with the following command:

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

Available options:

```
'take_redirect_to' => '/',
'leave_redirect_to' => '/'
```

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Chad Hurin](https://github.com/dhadhurin)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

985d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/57ae97edf58fa8cb6601f13bf050ad0848c8c9fe078626730ed9243c3d1777e6?d=identicon)[churin](/maintainers/churin)

---

Top Contributors

[![chadhurin](https://avatars.githubusercontent.com/u/7842802?v=4)](https://github.com/chadhurin "chadhurin (2 commits)")

---

Tags

chadhurinlaravel-masquerade

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/chadhurin-laravel-masquerade/health.svg)

```
[![Health](https://phpackages.com/badges/chadhurin-laravel-masquerade/health.svg)](https://phpackages.com/packages/chadhurin-laravel-masquerade)
```

###  Alternatives

[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)[olssonm/l5-very-basic-auth

Laravel stateless HTTP basic auth without the need for a database

1662.5M1](/packages/olssonm-l5-very-basic-auth)[stechstudio/laravel-jwt

Helper package that makes it easy to generate, consume, and protect routes with JWT tokens in Laravel

126117.6k](/packages/stechstudio-laravel-jwt)[scaler-tech/laravel-saml2

SAML2 Service Provider integration for Laravel applications, based on OneLogin toolkit

2737.5k](/packages/scaler-tech-laravel-saml2)[truckersmp/steam-socialite

Laravel Socialite provider for Steam OpenID.

1516.7k](/packages/truckersmp-steam-socialite)

PHPackages © 2026

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