genealabs/laravel-impersonator
Impersonate users in your Laravel 5.4+ app.
313,443
62
| Install | |
|---|---|
composer require genealabs/laravel-impersonator |
|
| Latest Version: | 13.0.0 |
| PHP: | ^8.2 |
| License: | MIT |
| Last Updated: | Mar 29, 2026 |
| Links: | GitHub · Packagist |
Maintainer: mikebronner
Impersonator for Laravel
Supporting This Package
This is an MIT-licensed open source project with its ongoing development made possible by the support of the community. If you'd like to support this, and our other packages, please consider becoming a backer or sponsor on Patreon.
Pre-requisites
- Laravel 10.0+
- PHP 8.2+
Version Support Matrix
| Laravel | PHP |
|---|---|
| 10.x | 8.2, 8.3, 8.4, 8.5 |
| 11.x | 8.2, 8.3, 8.4, 8.5 |
| 12.x | 8.2, 8.3, 8.4, 8.5 |
| 13.x | 8.3, 8.4, 8.5 |
Installation
composer require genealabs/laravel-impersonator
Configuration
genealabs-laravel-impersonator.layout: master blade layout view for your application (defaultlayouts.app).genealabs-laravel-impersonator.content-section: name of content section in master layout blade view (defaultcontent).genealabs-laravel-impersonator.user-model: user model of your application (defaultconfig('auth.providers.users.model')).genealabs-laravel-impersonator.middleware: the middleware to use for the impersonatee routes (default:['web', 'auth']). You may specifyonlyorexceptparameters. E.g.['web', 'auth', 'password.confirm' => ['except' => 'destroy']]
If you need to customize these settings:
php artisan impersonator:publish --config
Usage
- Add trait
GeneaLabs\LaravelImpersonator\Traits\Impersonatableto your user model. - Override trait method
public function getCanImpersonateAttribute() : boolthat determines if a given user can impersonate other users. - (optional) Override trait method
public function getCanBeImpersonatedAttribute() : boolthat determines if a given user can be impersonated. - Use
route('impersonatees.index')to view a list of all impersonatable users. You could add something like the following to your menu:
@if ((auth()->user()->canImpersonate ?? false) && ! session('impersonator'))
<a class="dropdown-item" href="{{ route('impersonatees.index') }}">Impersonator</a>
@endif
- (optional) Add something like the following to your menu view to allow imporsonator to stop impersonating:
@if (session('impersonator'))
<a href="{{ url('/logout') }}"
class="dropdown-item"
onclick="event.preventDefault(); document.getElementById('end-personation-session-form').submit();"
>
End Impersonation Session
</a>
<form action="{{ route('impersonatees.destroy', auth()->user()) }}"
method="POST"
style="display: none;"
id="end-personation-session-form"
>
{{ csrf_field () }}
{{ method_field ('DELETE') }}
</form>
@else
<a href="{!! route('logout') !!}"
class="dropdown-item"
onclick="event.preventDefault(); document.getElementById('logout-form').submit();">
Logout
</a>
<form method="POST"
action="{{ route('logout') }}"
accept-charset="UTF-8"
id="logout-form"
style="display:none;"
>
{{ csrf_field () }}
</form>
@endif
Customization
php artisan impersonator:publish --views
Credits
In large part prodded and inspired by LaraCasts' tutorial: https://laracasts.com/series/how-do-i/episodes/17. Thank you @JeffreyWay!
Related Packages
doctrine/dbal
Powerful PHP database abstraction layer (DBAL) with many features for database s...
641,106,524
9,700
laravel/serializable-closure
Laravel Serializable Closure provides an easy and secure way to serialize closur...
413,412,504
609
nunomaduro/collision
Cli error handling for console/command-line PHP applications.
394,964,158
4,660
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 13.0.0 | ^8.2 | ^11.0| | MIT | |
| 10.0.0 | ^10.0 | MIT | ||
| 9.0 | ^9.0 | MIT | ||
| 8.0.1 | ^8.0 | MIT | ||
| 8.0.0 | ^8.0 | MIT | ||
| 7.0.2 | ^7.0 | MIT | ||
| 7.0.1 | ^6.0| | MIT | ||
| 7.0.0 | ^7.0 | MIT | ||
| 1.0.1 | >=7.1.3 | ^5.5| | MIT | |
| 1.0.0 | >=7.1.3 | 5.5 - 6.0 | MIT | |
| 0.3.2 | >=7.1.3 | 5.5 - 5.8 | MIT | |
| 0.3.1 | >=7.1.3 | 5.5 - 5.8 | MIT | |
| 0.3.0 | >=7.1.3 | 5.5 - 5.8 | MIT | |
| 0.2.10 | >=7.1.3 | 5.5 - 5.7 | MIT | |
| 0.2.9 | >=7.1.3 | 5.5 - 5.7 | MIT | |
| 0.2.8 | >=7.1.3 | 5.5 - 5.7 | MIT | |
| 0.2.7 | >=7.1.3 | 5.5 - 5.7 | MIT | |
| 0.2.6 | >=7.1.3 | 5.5 - 5.7 | MIT | |
| 0.2.5 | >=7.1.3 | 5.5 - 5.7 | MIT | |
| 0.2.4 | >=7.1.3 | 5.5 - 5.7 | MIT | |
| 0.2.3 | >=7.0.0 | 5.5.* | MIT | |
| 0.2.1 | >=7.0.0 | 5.5.* | MIT | |
| 0.2.0 | >=7.0.0 | 5.5.* | MIT | |
| 0.1.2 | >=7.0.0 | 5.4.* | MIT | |
| 0.1.1 | >=7.0.0 | 5.4.* | MIT | |
| 0.1.0 | >=7.0.0 | MIT |