Allows a user to impersonate another user.
christhompsontldr/impersonate is a Laravel package for allows a user to impersonate another user..
It currently has 0 GitHub stars and 469 downloads on Packagist (latest version v2.0.0).
Install it with composer require christhompsontldr/impersonate.
Discover more Laravel packages by christhompsontldr
or browse all Laravel packages to compare alternatives.
Last updated
Allow a user to impersonate another user.
Require this package with composer:
composer require christhompsontldr/impersonate
After updating composer, add the ServiceProvider to the providers array in config/app.php
Christhompsontldr\Impersonate\ImpersonateServiceProvider::class,
This will apply a trait to the user model configured in config/auth.php. setup runs both the add-trait and publish commands.
php artisan impersonate:setup
This will run two commands (which can be run independently):
php artisan impersonate:add-trait
php artisan impersonate:publish
publish publishes the config and add-trait applies a trait to the user model.
You must complete this step, or none of your users will have permission to impersonate.
The authorized users that can impersonate and which users they can impersonate is controlled via the trait. This can be overloaded on your user model
In this example, the user model has an is_admin attribute that is being checked.
public function canImpersonate($id)
{
return $this->is_admin ?: false;
}
Or if you are using Laratrust
public function canImpersonate($id)
{
return $this->hasRole('admin');
}
Log out will be performed on both the main user and the impersonated user.
This package is based off an this example.