stechstudio/filament-impersonate
Filament plugin to impersonate users from your admin panel. Add an Impersonate action to resource tables or page header actions, with optional guard and redirect target. Supports SPA panels with an option to force full page loads when needed.
composer require stechstudio/filament-impersonate
UserResource table actions (e.g., app/Filament/Resources/UserResource.php):
use STS\FilamentImpersonate\Actions\Impersonate;
public static function table(Table $table): Table
{
return $table
->columns([...])
->actions([
Impersonate::make(),
]);
}
EditUser header actions (e.g., app/Filament/Resources/UserResource/Pages/EditUser.php):
protected function getHeaderActions(): array
{
return [
Impersonate::make()->record($this->getRecord()),
];
}
<x-impersonate::banner />
Debugging as a user:
UserResource table.Table Actions:
Impersonate::make() in table() for list views.guard() or redirectTo():
Impersonate::make()
->guard('custom-guard')
->redirectTo(route('dashboard'));
Page Actions:
Impersonate::make()->record($record) in getHeaderActions() for edit/create forms.Impersonate::make()->record($this->record)->withoutSpa();
Programmatic Impersonation:
if (Impersonation::isImpersonating()) {
Impersonation::leave();
}
Authorization:
canImpersonate() to the impersonator model (e.g., User):
public function canImpersonate(): bool
{
return $this->is_admin;
}
canBeImpersonated() to the target model:
public function canBeImpersonated(): bool
{
return !$this->is_super_admin;
}
->withoutSpa() if redirecting to non-Livewire pages.EnterImpersonation/LeaveImpersonation:
use STS\FilamentImpersonate\Events\EnterImpersonation;
EnterImpersonation::dispatch($impersonator, $impersonated);
zh_CN, ms). Override via config/filament-impersonate.php.403 Errors in List Views:
InteractsWithPageTable, add a guard clause to UserPolicy::viewAny():
public function viewAny(User $user): bool
{
if (Impersonation::isImpersonating()) return true;
return $user->canAccessFilament();
}
Soft-Deleted Users:
.env:
FILAMENT_IMPERSONATE_ALLOW_SOFT_DELETED=true
Octane Compatibility:
Missing Record in Page Actions:
$this->getRecord() to Impersonate::make() in EditUser.Failed Impersonation:
Log::warning).guard() parameter or panel config).Banner Not Showing:
<x-impersonate::banner /> is in non-Filament layouts.php artisan view:clear).Custom Banner:
resources/views/vendor/filament-impersonate/banner.blade.php).<x-impersonate::banner style="light" :display="auth()->user()->email" />
Custom Events:
EnterImpersonation/LeaveImpersonation for analytics or logging.Guard-Specific Logic:
guard() to handle multi-guard apps:
Impersonate::make()->guard('api');
Impersonation::enter($from, $to) in tests:
$this->actingAs($admin)
->call('POST', '/impersonate', ['user_id' => $user->id]);
LeaveImpersonation listeners.canImpersonate()/canBeImpersonated() results if models are large.How can I help you explore Laravel packages today?