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

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

victoryoalli/laravel-multitenancy-impersonate
=============================================

Laravel Multitenancy Impersonation from landlord to tenant

v2.4.0(1mo ago)58984MITPHPPHP ^8.0CI passing

Since Sep 12Pushed 1mo agoCompare

[ Source](https://github.com/victoryoalli/laravel-multitenancy-impersonate)[ Packagist](https://packagist.org/packages/victoryoalli/laravel-multitenancy-impersonate)[ Docs](https://github.com/victoryoalli/multitenancy-impersonate)[ Fund](https://victoryoalli.me/open-source/support-us)[ GitHub Sponsors](https://github.com/victoryoalli)[ RSS](/packages/victoryoalli-laravel-multitenancy-impersonate/feed)WikiDiscussions main Synced today

READMEChangelog (5)Dependencies (21)Versions (8)Used By (0)

Laravel Multitenancy Impersonate
================================

[](#laravel-multitenancy-impersonate)

Laravel multitenancy impersonation from landlord to tenant.

This package is made to be used with [Spatie Laravel Multitenancy](https://github.com/spatie/laravel-multitenancy).

[![Latest Version on Packagist](https://camo.githubusercontent.com/ec29ed6511df13025fe09001dd1bcd7c7958a831956fc78c0095968e7a4ea02a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f766963746f72796f616c6c692f6c61726176656c2d6d756c746974656e616e63792d696d706572736f6e6174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/victoryoalli/laravel-multitenancy-impersonate)[![Tests](https://github.com/victoryoalli/laravel-multitenancy-impersonate/actions/workflows/tests.yml/badge.svg)](https://github.com/victoryoalli/laravel-multitenancy-impersonate/actions/workflows/tests.yml)[![Total Downloads](https://camo.githubusercontent.com/376accf9ffb1f825d923a26f2691a8479ea545858eaf36d9bed426732cd2d1a4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f766963746f72796f616c6c692f6c61726176656c2d6d756c746974656e616e63792d696d706572736f6e6174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/victoryoalli/laravel-multitenancy-impersonate)

This package allows you to impersonate users from a landlord (main) application into tenant applications. It generates secure, time-limited tokens that enable seamless authentication across tenant databases.

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

[](#requirements)

- PHP ^8.2
- Laravel ^10.0, ^11.0 or ^12.0
- [Spatie Laravel Multitenancy](https://github.com/spatie/laravel-multitenancy) ^3.0 or ^4.0

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

[](#installation)

You can install the package via composer:

```
composer require victoryoalli/laravel-multitenancy-impersonate
```

Publish Config and Migrations
-----------------------------

[](#publish-config-and-migrations)

```
php artisan vendor:publish --provider="VictorYoalli\MultitenancyImpersonate\MultitenancyImpersonateServiceProvider"
```

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

[](#configuration)

After publishing, you can modify `config/multitenancy-impersonate.php`:

```
return [
    'ttl' => 60,                // Token lifetime in seconds
    'redirect_path' => '/home', // Default redirect after impersonation
    'auth_guard' => 'web',      // Authentication guard to use
    'rate_limit' => [
        'max_attempts' => 5,    // Max token validation attempts
        'decay_minutes' => 1,   // Minutes until attempts reset
    ],
];
```

Usage
-----

[](#usage)

### Landlord Controller

[](#landlord-controller)

The Landlord controller creates the token and redirects to the tenant for automatic login.

```
use VictorYoalli\MultitenancyImpersonate\Traits\CanImpersonate;

class ImpersonateController
{
    use CanImpersonate;

    public function store(Request $request)
    {
        $tenant = Tenant::find($request->get('tenant_id'));
        $redirect_url = "https://{$tenant->domain}/admin";

        // Create impersonation token in tenant's database
        $impersonate = $this->createToken($tenant, auth()->user(), $redirect_url);

        // Redirect to tenant's impersonation endpoint
        $tenant_url = "https://{$tenant->domain}/impersonate";

        return redirect("{$tenant_url}/{$impersonate->token}");
    }
}
```

### Tenant Controller

[](#tenant-controller)

Validates the token and logs in the specified user. The user will be redirected to the `$redirect_url` provided when creating the token.

```
use VictorYoalli\MultitenancyImpersonate\Traits\CanImpersonate;

class TenantImpersonateController
{
    use CanImpersonate;

    public function __invoke(Request $request, string $token)
    {
        $user = User::firstOrFail(); // Or find user by any criteria

        return $this->impersonate($token, $user);
    }
}
```

### 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)

- [Victor Yoalli](https://github.com/victoryoalli)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

51

—

FairBetter than 95% of packages

Maintenance90

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity65

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 ~415 days

Recently: every ~34 days

Total

6

Last Release

45d ago

Major Versions

0.0.1 → v2.0.02026-01-02

PHP version history (4 changes)0.0.1PHP ^7.4

v2.0.0PHP ^8.1

v2.1.0PHP ^8.2

v2.2.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/488202a656e6be4d5992b6c2d7bb91155587fa7144279b5c52f671b5d88eb24e?d=identicon)[victoryoalli](/maintainers/victoryoalli)

---

Top Contributors

[![victoryoalli](https://avatars.githubusercontent.com/u/141497?v=4)](https://github.com/victoryoalli "victoryoalli (31 commits)")

---

Tags

laravelimpersonatemultitenancyvictoryoalli

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k102.4M1.4k](/packages/spatie-laravel-permission)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k15.1M131](/packages/laravel-pulse)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M345](/packages/psalm-plugin-laravel)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M194](/packages/laravel-ai)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)

PHPackages © 2026

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