You can install the package via composer:
composer require pentangle/laravel-backpack-impersonation-addon
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' => '/',
The MIT License (MIT). Please see License File for more information.