pentangle/laravel-backpack-impersonation-addon

Backpack for Laravel Addon allows backpack users to impersonate other users

1.0.2 2022-03-02 12:34 UTC

This package is auto-updated.

Last update: 2024-10-29 06:36:20 UTC


README

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.