Impersonation
Learn how to impersonate other users in your application.
Overview
After deploying your application to production, you may occasionally need to “impersonate” another user of your application in order to debug problems your customers are reporting. Thankfully, Nova includes built-in functionality to handle this exact scenario.
Enabling Impersonation
To enable user impersonation, add the Laravel\Nova\Auth\Impersonatable
trait to your application’s User
model:
Once the Impersonatable
trait has been added to your application’s User
model, an “Impersonate” action will be available via the inline action menu for the corresponding resource:
Customizing Impersonation Authorization
By default, any user that has permission to view the Nova dashboard can impersonate any other user. However, you may customize who can impersonate other users and what users can be impersonated by defining canImpersonate
and canBeImpersonated
methods on your application’s Impersonatable
model:
Inspecting Impersonation State
By resolving an implementation of the Laravel\Nova\Contracts\ImpersonatesUsers
interface via Laravel’s service container, you can inspect the current impersonation state of the application:
Impersonation Events
By default, you add additional customisation by using available events for Impersonations:
Laravel\Nova\Events\StartedImpersonating
Laravel\Nova\Events\StoppedImpersonating
For example, you may want to log impersonation events, which you can register listeners for in the boot
method of your application’s AppServiceProvider
: