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

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

alp-develop/laravel-impersonate
===============================

Secure user impersonation for Laravel applications

v1.0.0(1mo ago)025MITPHPPHP ^8.1CI passing

Since Apr 12Pushed 1mo agoCompare

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

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

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

[](#laravel-impersonate)

[![Version](https://camo.githubusercontent.com/b919c80b5d7a1d3eb4f4c1790f3953516d0d917554e797dbaf28fe39038c412d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f616c702d646576656c6f702f6c61726176656c2d696d706572736f6e6174653f6c6162656c3d76657273696f6e267374796c653d666c61742d73717561726526736f72743d73656d766572)](https://packagist.org/packages/alp-develop/laravel-impersonate)[![Tests](https://camo.githubusercontent.com/09bbb3375d7df1976a3ec5ebf02a157445497e725120ab30c8e2899ad4c6e5d2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616c702d646576656c6f702f6c61726176656c2d696d706572736f6e6174652f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/alp-develop/laravel-impersonate/actions/workflows/tests.yml)[![License](https://camo.githubusercontent.com/195d1e268b3e5600cf36b6c1685554a2236edd9ced9863e686c6be30767f01d7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f616c702d646576656c6f702f6c61726176656c2d696d706572736f6e6174653f7374796c653d666c61742d737175617265)](https://github.com/alp-develop/laravel-impersonate/blob/main/LICENSE)

Secure user impersonation for Laravel applications. Built with a session-based architecture, versioned context, automatic validation middleware, and a full event system.

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

[](#requirements)

- PHP 8.1+
- Laravel 10.x, 11.x , 12.x or 13.x

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

[](#installation)

```
composer require alp-develop/laravel-impersonate
```

Publish the configuration file:

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

Quick Start
-----------

[](#quick-start)

### 1. Implement the contract on your User model

[](#1-implement-the-contract-on-your-user-model)

```
use AlpDevelop\LaravelImpersonate\Contracts\Impersonatable;
use AlpDevelop\LaravelImpersonate\Traits\HasImpersonation;

class User extends Authenticatable implements Impersonatable
{
    use HasImpersonation;
}
```

### 2. Define a Gate policy

[](#2-define-a-gate-policy)

The package registers an `impersonate` gate that returns `false` by default. Override it in your `AuthServiceProvider`:

```
use Illuminate\Support\Facades\Gate;

Gate::define('impersonate', function ($user, $target) {
    return $user->is_admin;
});
```

### 3. Start and stop impersonation

[](#3-start-and-stop-impersonation)

```
use AlpDevelop\LaravelImpersonate\Facades\Impersonate;

Impersonate::start($targetUser);
Impersonate::start($targetUser, ttl: 30);
Impersonate::stop();
```

Documentation
-------------

[](#documentation)

SectionDescription[Configuration](docs/configuration.md)All config options with types, defaults and examples[Authorization](docs/authorization.md)Three-layer authorization model, validation order, role-based examples[Middleware](docs/middleware.md)HandleImpersonation and ForbidDuringImpersonation setup and behavior[Events](docs/events.md)All 5 events with payloads, listener examples, and flow diagram[API Reference](docs/api-reference.md)Full reference: Facade, Contract, Trait, Value Object, Enum, Macros, Blade directives[Security](docs/security.md)Session regeneration, versioned context, automatic validation, IP tracking, recommendationsTesting
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for recent changes.

License
-------

[](#license)

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

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance89

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

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

58d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/264593454?v=4)[alp-develop](/maintainers/alp-develop)[@alp-develop](https://github.com/alp-develop)

---

Top Contributors

[![alp-develop](https://avatars.githubusercontent.com/u/264593454?v=4)](https://github.com/alp-develop "alp-develop (1 commits)")

---

Tags

impersonatelaraveluser-impersonatelaravelimpersonationimpersonateuser-switching

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3325.1M337](/packages/psalm-plugin-laravel)[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.1k91.3M277](/packages/laravel-horizon)[illuminate/database

The Illuminate Database package.

3.0k54.1M11.0k](/packages/illuminate-database)[laravel/ai

The official AI SDK for Laravel.

9782.1M153](/packages/laravel-ai)[moonshine/moonshine

Laravel administration panel

1.3k239.9k72](/packages/moonshine-moonshine)[illuminate/auth

The Illuminate Auth package.

9327.9M1.2k](/packages/illuminate-auth)

PHPackages © 2026

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