定制 genealabs/laravel-impersonator 二次开发

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

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

genealabs/laravel-impersonator

最新稳定版本:10.0.0

Composer 安装命令:

composer require genealabs/laravel-impersonator

包简介

Impersonate users in your Laravel and Nova apps.

README 文档

README

Laravel Package codecov

Impersonator for Laravel

Impersonator for Laravel masthead image.

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 8.0+
  • PHP 7.3+

Installation

composer require genealabs/laravel-impersonator

Configuration

  • genealabs-laravel-impersonator.layout: master blade layout view for your application (default layouts.app).
  • genealabs-laravel-impersonator.content-section: name of content section in master layout blade view (default content).
  • genealabs-laravel-impersonator.user-model: user model of your application (default config('auth.providers.users.model')).
  • genealabs-laravel-impersonator.middleware: the middleware to use for the impersonatee routes (default: ['web', 'auth']). You may specify only or except parameters. E.g. ['web', 'auth', 'password.confirm' => ['except' => 'destroy']]

If you need to customize these settings:

php artisan impersonator:publish --config

Usage

  1. Add trait GeneaLabs\LaravelImpersonator\Traits\Impersonatable to your user model.
  2. Override trait method public function getCanImpersonateAttribute() : bool that determines if a given user can impersonate other users.
  3. (optional) Override trait method public function getCanBeImpersonatedAttribute() : bool that determines if a given user can be impersonated.
  4. 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
  1. (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!

统计信息

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

GitHub 信息

  • Stars: 62
  • Watchers: 1
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固