pentangle / laravel-backpack-impersonation-addon
Backpack for Laravel Addon allows backpack users to impersonate other users
Fund package maintenance!
Pentangle
Requires
- php: ^8.0
- backpack/crud: ^4.1|^5.0
- illuminate/support: ~8|~9
- lab404/laravel-impersonate: ^1.7
- spatie/laravel-package-tools: ^1.9
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^9.5
- spatie/ray: ^1.28
- vimeo/psalm: ^4.8
README
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.