Impersonation
Sign in as a user from the admin to see what they see, with a ribbon on every page until you leave. Two Blade partials over lab404/laravel-impersonate.


What it adds
| File | Purpose |
|---|---|
resources/views/partials/impersonation-banner.blade.php | The ribbon. <x-ui-kit::banners /> includes it automatically when impersonating. |
resources/views/partials/impersonation-button.blade.php | A Login as button for a user row |
canImpersonate() and canBeImpersonated() in app/Models/Concerns/UiKitUser.php | Admins can impersonate; nobody can impersonate an admin |
Install
php artisan ui-kit:install-module impersonation
Composer: lab404/laravel-impersonate:^1.7.5.
What the installer changes
- Publishes the package config to
config/laravel-impersonate.php. - Regenerates the
UiKitUsertrait with the two methods and re-applies it. - Adds
Route::impersonate();between the markers inroutes/ui-kit-user.php, which registersGET /impersonate/take/{id}asimpersonateandGET /impersonate/leaveasimpersonate.leave, both underwebandauth.lab404/laravel-impersonateships those routes as a router macro the app has to call; the installer calls it so the partials have something to link to.ui-kit:doctorchecks both names exist.
Installed the module before this was automated and added the macro to
routes/web.php yourself? Remove that line after re-running php artisan ui-kit:install-module impersonation, otherwise the doctor reports the two
names as duplicates.
The button
The admin user detail page shows Login as beside the user's name on its own: since 0.4.1 its view includes the partial whenever it exists, with @includeIf('partials.impersonation-button', ['user' => $user]). ui-kit:doctor checks it under impersonation button wired. A user detail view published by 0.4.0 or earlier lacks the line; add it, or re-run the installer with --force.
For screens of your own, include the partial next to each user:
@include('partials.impersonation-button', ['user' => $user])
It renders only when the current user can impersonate, the target can be impersonated, and the two are not the same user. Admins cannot be impersonated.
After taking over
The package redirects to take_redirect_to from its config, / by default, and the ribbon appears on every page that renders <x-ui-kit::banners />, which all three kit layouts do. Exit impersonation in the ribbon returns you to your own session.
Removing
Delete the two partials, remove the Route::impersonate(); line from routes/ui-kit-user.php and the @include, remove the two methods from the trait, remove impersonation from installed_modules, and composer remove lab404/laravel-impersonate. The routes line has to go before the package does, or the next request fails on the missing macro.