Package Data | |
---|---|
Maintainer Username: | ChrisThompsonTLDR |
Maintainer Contact: | christhompsontldr@gmail.com (Chris Thompson) |
Package Create Date: | 2020-01-15 |
Package Last Update: | 2020-10-13 |
Language: | PHP |
License: | Unknown |
Last Refreshed: | 2024-12-16 15:01:32 |
Package Statistics | |
---|---|
Total Downloads: | 468 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
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.