PHPackages                             maurohmartinez/impersonate-users-backpack-laravel - 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. maurohmartinez/impersonate-users-backpack-laravel

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

maurohmartinez/impersonate-users-backpack-laravel
=================================================

A simple package that adds the impersonate operation for admins

1.1.7(5mo ago)118.8k↓13.6%4[1 issues](https://github.com/maurohmartinez/impersonate-users-backpack-laravel/issues)MITPHPPHP ^8.0

Since Jul 18Pushed 5mo ago2 watchersCompare

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

READMEChangelog (10)Dependencies (2)Versions (24)Used By (0)

Impersonate users with Backpack for Laravel
===========================================

[](#impersonate-users-with-backpack-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d6daf208385a827abc00148a9b6a8d7d5944e9d0e9d252e842e53a7463d1db33/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6175726f686d617274696e657a2f696d706572736f6e6174652d75736572732d6261636b7061636b2d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/maurohmartinez/impersonate-users-backpack-laravel)[![Total Downloads](https://camo.githubusercontent.com/24fafa562ac7fa91f6414eb08ac844afacd42639755585b2ac5fad7ae8971a82/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6175726f686d617274696e657a2f696d706572736f6e6174652d75736572732d6261636b7061636b2d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/maurohmartinez/impersonate-users-backpack-laravel)

This is a simple package to allow admins impersonate users.

[![alt text](https://github.com/maurohmartinez/impersonate-users-backpack-laravel/raw/main/src/sample.gif?raw=true)](https://github.com/maurohmartinez/impersonate-users-backpack-laravel/blob/main/src/sample.gif?raw=true)

Install
-------

[](#install)

In your terminal:

```
# install the package
composer require maurohmartinez/impersonate-users-backpack-laravel
```

In case you want/need to publish files to further customize this package:

```
php artisan vendor:publish --provider="MHMartinez\ImpersonateUser\app\Providers\ImpersonateUserServiceProvider"
```

Usage
-----

[](#usage)

1- Add in your `UserCrudController`.

```
use \MHMartinez\ImpersonateUser\app\Http\Controllers\Operations\ImpersonateUserOperation;
```

This will add a button for List and Show Operations to impersonate users.

2- Next step is to handle the logic to indicate which admins have permission to impersonate others, or can be impersonated. You just need to modify a bit your `User Model` to implement the interface `ImpersonateInterface` like this:

```
class User extends Authenticatable implements ImpersonateInterface
```

And then add the following two methods in your `User Model`:

```
/**
 * If you use Laravel-Backpack/PermissionManager you can do like this.
 * But you can also add any logic you need.
*/
public function canImpersonateOthers(): bool
{
    return $this->can('permission_to_impersonate'); // or replace "permission_to_impersonate" with the right permission
}
/**
 * Following the same example, you can deny admins from impersonating super admins.
*/
public function canBeImpersonated(): bool
{
    return !$this->hasRole('superadmin'); // or replace "superadmin" with the right permission
}
```

3- Now, you just need to add the button to exit impersonating (no worries, it will only show up when needed). For example, you can add the button in `topbar_right_content.blade.php` like this:

```
@include('impersonate_user::exit_impersonated')
```

4- Important — If you want to impersonate non-admin users you will need to skip the backpack middleware that determines if the user is admin. This is because this operation will need to allow your impersonated non-admin user to use a backpack route to log you back. How to do it?

- Publish the config file if you haven't done so (described here, above step one).

```
php artisan vendor:publish --provider="MHMartinez\ImpersonateUser\app\Providers\ImpersonateUserServiceProvider" --tag=config
```

- Add the middleware classname like it follows, and you will be good to go:

```
return [
    'session_key' => 'impersonating_user',
    'base_guard' => 'backpack',
    'admin_middleware' => Path\To\Middleware\IsAdmin::class,
    'skip_middlewares' => [],
];
```

This will allow this operation to skip that middleware when logging out impersonated non-admin users.

Credits
-------

[](#credits)

- [Mauro Martinez](https://inspiredpulse.com/) Developer
- [Cristian Tabacitu](https://tabacitu.ro/) For creating [Backpack for Laravel](https://backpackforlaravel.com/)!

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance69

Regular maintenance activity

Popularity33

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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

Every ~56 days

Recently: every ~75 days

Total

23

Last Release

165d ago

PHP version history (2 changes)v1.0.0PHP ^7.3|^8.0

1.1.1PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/21192abc454e8b809201f9150490b1b6f694cfdf3e6494d04fb915b9fb1e697d?d=identicon)[maurohmartinez](/maintainers/maurohmartinez)

---

Top Contributors

[![maurohmartinez](https://avatars.githubusercontent.com/u/33960976?v=4)](https://github.com/maurohmartinez "maurohmartinez (32 commits)")

---

Tags

backpacklaravellaravelbackpackforce ssl

### Embed Badge

![Health badge](/badges/maurohmartinez-impersonate-users-backpack-laravel/health.svg)

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

###  Alternatives

[lab404/laravel-impersonate

Laravel Impersonate is a plugin that allows to you to authenticate as your users.

2.3k16.4M48](/packages/lab404-laravel-impersonate)[santigarcor/laratrust

This package provides a flexible way to add Role-based Permissions to Laravel

2.3k5.4M43](/packages/santigarcor-laratrust)[pragmarx/google2fa-laravel

A One Time Password Authentication package, compatible with Google Authenticator.

1.0k15.5M63](/packages/pragmarx-google2fa-laravel)[codegreencreative/laravel-samlidp

Make your PHP Laravel application an Identification Provider using SAML 2.0. This package allows you to implement your own Identification Provider (idP) using the SAML 2.0 standard to be used with supporting SAML 2.0 Service Providers (SP).

263763.5k1](/packages/codegreencreative-laravel-samlidp)[jeremy379/laravel-openid-connect

OpenID Connect support to the PHP League's OAuth2 Server. Compatible with Laravel Passport.

55342.3k2](/packages/jeremy379-laravel-openid-connect)

PHPackages © 2026

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