PHPackages                             adjarriawan/laravel-impersonate - 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. adjarriawan/laravel-impersonate

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

adjarriawan/laravel-impersonate
===============================

Login as a different user quickly

016PHP

Since Feb 1Pushed 3y agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

 [![Demo](demo.gif)](demo.gif)

 [![Tests](https://camo.githubusercontent.com/5791e88f2c9ecbd9e81b23c18bc04ae785871788cbb802ea8a1bc132d64df9a8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f4f63746f707949442f4c617261506572736f6e6174652f74657374732e796d6c3f6272616e63683d6d61696e267374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/5791e88f2c9ecbd9e81b23c18bc04ae785871788cbb802ea8a1bc132d64df9a8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f4f63746f707949442f4c617261506572736f6e6174652f74657374732e796d6c3f6272616e63683d6d61696e267374796c653d666f722d7468652d6261646765) [![Version](https://camo.githubusercontent.com/290cc4baf398b6c874d633045aba56d709bf901d9ad310ae8129f211937ebbae/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f63746f707969642f6c61726176656c2d696d706572736f6e6174652e7376673f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/290cc4baf398b6c874d633045aba56d709bf901d9ad310ae8129f211937ebbae/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f63746f707969642f6c61726176656c2d696d706572736f6e6174652e7376673f7374796c653d666f722d7468652d6261646765) [![Downloads](https://camo.githubusercontent.com/7f07985e56f1aa1829258a5b57664b459575cb820df7a5dbd11b88279e6a749f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f63746f707969642f6c61726176656c2d696d706572736f6e6174652e7376673f7374796c653d666f722d7468652d626164676526636f6c6f723d463238443141)](https://camo.githubusercontent.com/7f07985e56f1aa1829258a5b57664b459575cb820df7a5dbd11b88279e6a749f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f63746f707969642f6c61726176656c2d696d706572736f6e6174652e7376673f7374796c653d666f722d7468652d626164676526636f6c6f723d463238443141) [![License](https://camo.githubusercontent.com/dea71c3b7b79e68c6c0012ea6ce0016d1c750404bbd856492466f5ac14f38076/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6f63746f707969642f6c61726176656c2d696d706572736f6e6174652e7376673f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/dea71c3b7b79e68c6c0012ea6ce0016d1c750404bbd856492466f5ac14f38076/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6f63746f707969642f6c61726176656c2d696d706572736f6e6174652e7376673f7374796c653d666f722d7468652d6261646765)

Laravel Impersonate
===================

[](#laravel-impersonate)

Is an Impersonation package for the Laravel Framework. With this package you can easily impersonate other users either manually or using the interface we provide.

You don't have to worry about authorizing who can impersonate or who can be impersonated, coz we provided it by default, just need to adjust it a little according to your rules.

1. Installation
---------------

[](#1-installation)

> **Warning**
>
> This version is a breaking change, many changes were made to the addition of new features, new UI design, and code structure.
>
> If you are upgrade from an old version, please delete the old assets and republish the assets, configure and reset the [limitations](#311-defining-limitation) on the User Model according to this version.

To install the package, simply follow the steps below.

### 1.1. Install The Package

[](#11-install-the-package)

```
composer require octopyid/laravel-impersonate:^3
```

### 1.2. Publish The Package

[](#12-publish-the-package)

```
artisan vendor:publish --provider="Octopy\Impersonate\ImpersonateServiceProvider"
```

> **Note**
>
> Sometimes some users experience the problem of layout after upgrading the package, this can be solved by deleting the `public/vendor/octopyid/impersonate` folder then republish the assets.

### 1.3. Add Impersonate Trait to User Model

[](#13-add-impersonate-trait-to--user-model)

Add the trait `Octopy\Impersonate\Concerns\Impersonate` to your **User** model.

```
namespace App\Models;

use Octopy\Impersonate\Cocerns\Impersonate;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Impersonate;
}
```

2. Configuration
----------------

[](#2-configuration)

This configuration is intended to customize the appearance of Laravel Impersonate, if you don't need a UI, don't forget to set `IMPERSONATE_ENABLED` to `false` in your environment file because it is enabled by default.

Please refer to the [impersonate.php](config/impersonate.php) file to see the available configurations.

3. Usage
--------

[](#3-usage)

### 3.1. Basic Usage

[](#31-basic-usage)

By default, you don't need to do anything, but keep in mind, Impersonation can be done by anyone if you don't define the rules of who can do impersonation or who can be impersonated.

#### 3.1.1. Defining Limitation

[](#311-defining-limitation)

To limit who can do **impersonation** or who is can be **impersonated**, add `impersonatable(ImpersonateAuthorization $authorization)` on the Model to enforce the limitation.

The **impersonator** method is intended for who can perform the impersonation and the **impersonated** method is intended for anyone who is allowed to be imitated.

> **Warning**
>
> Not defining the ImpersonateAuthorization rules in the Model or misdefining them can lead to serious security issues.

The example below uses [Laratrust](https://github.com/santigarcor/laratrust/) for role management where **SUPER\_ADMIN** can perform impersonation against **CUSTOMER**. Feel free to use any other Role Management you like.

```
use Octopy\Impersonate\Cocerns\Impersonate;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Impersonate;

    /**
     * @param  ImpersonateAuthorization $authorization
     * @return void
     */
    public function impersonatable(ImpersonateAuthorization $authorization) : void
    {
        $authorization->impersonator(function (User $user) {
            return $user->hasRole('SUPER_ADMIN');
        });

        $authorization->impersonated(function (User $user) {
            return $user->hasRole('CUSTOMER');
        });
    }
}
```

### 3.2. Advanced Usage

[](#32-advanced-usage)

#### 3.2.1. Impersonating User Manually

[](#321-impersonating-user-manually)

Sometimes you need Impersonating manually, to perform it, you can use the impersonate singleton.

```
$impersonate = App::make('impersonate');
$impersonate->take($admin, $customer);
```

Or you just simply call the impersonation method directly through the User Model.

```
$admin->impersonate($customer);
```

#### 3.2.2. Defining Guard

[](#322-defining-guard)

Sometimes, you want to use custom guards for authentication, instead of the built-in guards.

There are two ways to define Guard.

##### 3.2.2.1. On The Fly

[](#3221-on-the-fly)

```
$impersonate->guard('foo')->impersonate($admin, $customer);
```

##### 3.2.2.2 Globally

[](#3222-globally)

You can use Guard for all ImpersonateAuthorization actions by registering the guard with the `AppServiceProvider`.

```
public function boot() : void
{
    App::make('impersonate')->guard('foo');
}
```

#### 3.2.3. Leaving ImpersonateAuthorization Mode

[](#323-leaving-impersonateauthorization-mode)

To leave ImpersonateAuthorization mode, you just need to call the `leave` method on impersonate singleton. This will return you to the original user.

```
$impersonate->leave();
```

Or via Model directly, but you can't use guard on the fly.

```
$admin->impersonate->leave();
```

Don't hesitate to use a guard if you need it.

Disclaimer
----------

[](#disclaimer)

This package can pose a serious security issue if used incorrectly, as anybody will be able to take control of any user's account.

By using this package, you agree that Octopy ID and the contributors of this package cannot be held responsible for any damages caused by using this package.

Security
--------

[](#security)

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

Credits
-------

[](#credits)

- [Supian M](https://github.com/SupianIDz)
- [Octopy ID](https://github.com/OctopyID)

License
-------

[](#license)

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

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 Bus Factor1

Top contributor holds 99.2% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/059f40ce8e316623d5f74510fdbe60e067ed282ddf555b4b81ccf8c0afe1a093?d=identicon)[adjarriawan](/maintainers/adjarriawan)

---

Top Contributors

[![SupianIDz](https://avatars.githubusercontent.com/u/37969970?v=4)](https://github.com/SupianIDz "SupianIDz (119 commits)")[![adjarriawan](https://avatars.githubusercontent.com/u/37354675?v=4)](https://github.com/adjarriawan "adjarriawan (1 commits)")

### Embed Badge

![Health badge](/badges/adjarriawan-laravel-impersonate/health.svg)

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

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

41721.2M118](/packages/league-oauth2-google)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)

PHPackages © 2026

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