Skip to content

Pentangle/laravel-backpack-impersonation-addon

Repository files navigation

Backpack for Laravel Addon allows backpack users to impersonate other users

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Installation

You can install the package via composer:

composer require pentangle/laravel-backpack-impersonation-addon

Setup

add the trait to the desired user model

use UserImpersonationTrait;

override the existing functions by adding them to the model

    /**
     * @return bool
     */
    public function canImpersonate()
    {
        return true;
    }

    /**
     * @return bool
     */
    public function canBeImpersonated()
    {
        return true;
    }

    public function impersonateButton($crud = false)
    {
        return '<a href="'.route("impersonate", $this->id).'">Impersonate this user</a>';
    }

add the following code to your routes file web.php

Route::impersonate();

add the following code to the ModelCrudController

$this->crud->addButton('line', 'impersonateButton', 'model_function', 'impersonateButton');

Publish the config file to configure custom routes

php artisan vendor:publish --tag=impersonate

config/laravel-impersonate.php


    /**
     * The session key used to store the original user id.
     */
    'session_key' => 'impersonated_by',

    /**
     * The session key used to stored the original user guard.
     */
    'session_guard' => 'impersonator_guard',

    /**
     * The session key used to stored what guard is impersonator using.
     */
    'session_guard_using' => 'impersonator_guard_using',

    /**
     * The default impersonator guard used.
     */
    'default_impersonator_guard' => 'web',

    /**
     * The URI to redirect after taking an impersonation.
     *
     * Only used in the built-in controller.
     * * Use 'back' to redirect to the previous page
     */
    'take_redirect_to' => '/',

    /**
     * The URI to redirect after leaving an impersonation.
     *
     * Only used in the built-in controller.
     * Use 'back' to redirect to the previous page
     */
    'leave_redirect_to' => '/',

Credits

License

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

About

Backpack for Laravel Addon allows backpack users to impersonate other users

Resources

License

Security policy

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published