Configuration
Publish the config file:
php artisan vendor:publish --tag=impersonation-config
Options
| Key | Default | Purpose |
|---|---|---|
session_key | impersonation_data | Session key for the impersonation stack |
guard | null | Auth guard for default user/login handlers (null = default guard) |
max_depth | 1 | Maximum nested impersonation depth |
routing.enabled | false | Register package start/stop routes |
routing.prefix | impersonation | URL prefix for those routes |
routing.middleware | ['web', 'auth'] | Middleware applied to package routes |
routing.names.start | impersonation.start | Route name for start |
routing.names.stop | impersonation.stop | Route name for stop |
routing.impersonatee_model | App\Models\User | Model resolved from the {impersonatee} route parameter |
Depth
// config/impersonation.php
'max_depth' => 1, // Admin → User only
'max_depth' => 2, // Admin → User → Another user
When the stack is at max_depth, canImpersonate() returns false.
Guard
'guard' => 'web',
Default user and login handlers use Auth::guard($guard) (or the default guard when null).
Runtime overrides
ImpersonationConfig::set() and ImpersonationConfig::clearCache() are available
in tests. Prefer published config (or config([...]) before the app boots) in apps.
Continue to Usage.