定制 abdullyahuza/filament-impersonate 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

abdullyahuza/filament-impersonate

最新稳定版本:v1.0.0

Composer 安装命令:

composer require abdullyahuza/filament-impersonate

包简介

Filament Impersonate allows administrators to securely impersonate other users within the Filament admin panel. With a simple "Impersonate" action, admins can log in as another user to troubleshoot issues, test permissions, or preview user-specific content. A visible banner indicates impersonation m

README 文档

README

DEMO UI

🎭 Filament Impersonate

License: MIT

A plugin for Filament Admin Panel that allows authorized users to impersonate other users.

📦 Installation

composer require abdullyahuza/filament-impersonate

Optionally publish the config file:

php artisan vendor:publish --tag="filament-impersonate-config"

⚙️ Configuration

Inside config/filament-impersonate.php:

return [

    'redirect_after_impersonation' => 'filament.app.pages.dashboard',

    'guard' => 'web',

    'user_model' => \App\Models\User::class,

    'session_key' => 'filament_impersonator_id',

    'excluded_user_ids' => [/* user IDs that should never be impersonated */],

    'allowed_environments' => ['local', 'staging', 'production'],

    'display_name_resolver' => fn ($user) => $user->name ?? 'Unknown User',

    'can_impersonate_resolver' => fn ($user) => $user?->hasRole('admin') || $user?->can('impersonate users'),

];

Setup Filament-Impersonate

Install for Panel

->plugins([
	...
	FilamentImpersonate::make(),
])
->middleware([
	...
	// AuthenticateSession::class,
])

✅ Usage

Impersonate a user

  1. From the Filament UI, click the impersonation button shown next to user profile (if allowed).
  2. You will be logged in as that user.
  3. A banner or button will appear indicating impersonation — click it to stop impersonating.

Stop impersonating

Click the "Stop Impersonating" button to return to your original user session.

🔐 Permissions

To restrict who can impersonate users, configure the can_impersonate_resolver in your config file.

Example:

'can_impersonate_resolver' => fn ($user) => $user?->hasRole('admin') || $user?->can('impersonate_users'),

💾 Session Management

During impersonation, the following is stored in the session:

  • Impersonator ID
  • Original user roles & permissions (if applicable)

These are restored when impersonation is stopped.

🛡️ Notes

  • Only users not in excluded_user_ids can be impersonated.
  • Impersonation only works in environments defined in allowed_environments.
  • You can customize how user names are displayed using display_name_resolver.

🧪 Testing

Ensure your environment is included in allowed_environments for local testing.

'allowed_environments' => ['local'],

📄 License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-21