genealabs/laravel-impersonator
Composer 安装命令:
composer require genealabs/laravel-impersonator
包简介
Impersonate users in your Laravel and Nova apps.
README 文档
README
Impersonator for Laravel
Supporting This Package
This is an MIT-licensed open source project with its ongoing development made possible by the support of the community. If you'd like to support this, and our other packages, please consider becoming a backer or sponsor on Patreon.
Pre-requisites
- Laravel 10.0+
- PHP 8.2+
Version Support Matrix
| Laravel | PHP |
|---|---|
| 10.x | 8.2, 8.3, 8.4, 8.5 |
| 11.x | 8.2, 8.3, 8.4, 8.5 |
| 12.x | 8.2, 8.3, 8.4, 8.5 |
| 13.x | 8.3, 8.4, 8.5 |
Installation
composer require genealabs/laravel-impersonator
Configuration
genealabs-laravel-impersonator.layout: master blade layout view for your application (defaultlayouts.app).genealabs-laravel-impersonator.content-section: name of content section in master layout blade view (defaultcontent).genealabs-laravel-impersonator.user-model: user model of your application (defaultconfig('auth.providers.users.model')).genealabs-laravel-impersonator.middleware: the middleware to use for the impersonatee routes (default:['web', 'auth']). You may specifyonlyorexceptparameters. E.g.['web', 'auth', 'password.confirm' => ['except' => 'destroy']]
If you need to customize these settings:
php artisan impersonator:publish --config
Usage
- Add trait
GeneaLabs\LaravelImpersonator\Traits\Impersonatableto your user model. - Override trait method
public function getCanImpersonateAttribute() : boolthat determines if a given user can impersonate other users. - (optional) Override trait method
public function getCanBeImpersonatedAttribute() : boolthat determines if a given user can be impersonated. - Use
route('impersonatees.index')to view a list of all impersonatable users. You could add something like the following to your menu:
@if ((auth()->user()->canImpersonate ?? false) && ! session('impersonator')) <a class="dropdown-item" href="{{ route('impersonatees.index') }}">Impersonator</a> @endif
- (optional) Add something like the following to your menu view to allow imporsonator to stop impersonating:
@if (session('impersonator')) <a href="{{ url('/logout') }}" class="dropdown-item" onclick="event.preventDefault(); document.getElementById('end-personation-session-form').submit();" > End Impersonation Session </a> <form action="{{ route('impersonatees.destroy', auth()->user()) }}" method="POST" style="display: none;" id="end-personation-session-form" > {{ csrf_field () }} {{ method_field ('DELETE') }} </form> @else <a href="{!! route('logout') !!}" class="dropdown-item" onclick="event.preventDefault(); document.getElementById('logout-form').submit();"> Logout </a> <form method="POST" action="{{ route('logout') }}" accept-charset="UTF-8" id="logout-form" style="display:none;" > {{ csrf_field () }} </form> @endif
Customization
php artisan impersonator:publish --views
Credits
In large part prodded and inspired by LaraCasts' tutorial: https://laracasts.com/series/how-do-i/episodes/17. Thank you @JeffreyWay!
genealabs/laravel-impersonator 适用场景与选型建议
genealabs/laravel-impersonator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 274.11k 次下载、GitHub Stars 达 62, 最近一次更新时间为 2017 年 05 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 genealabs/laravel-impersonator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 genealabs/laravel-impersonator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 274.11k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 62
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-05-09