| Package Data | |
|---|---|
| Maintainer Username: | Bizhub |
| Maintainer Contact: | lex@bizhub.co.nz (Lex van der Woude) |
| Package Create Date: | 2016-10-20 |
| Package Last Update: | 2018-09-11 |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-10-18 15:19:45 |
| Package Statistics | |
|---|---|
| Total Downloads: | 5,542 |
| Monthly Downloads: | 0 |
| Daily Downloads: | 0 |
| Total Stars: | 2 |
| Total Watchers: | 1 |
| Total Forks: | 1 |
| Total Open Issues: | 0 |
Authenticate as another user while maintaining previous authentication.
This works by using Laravels Auth::onceUsingId() feature where you can authenticate
as a user for that request only. A middleware will check if you're impersonating via a session variable
and activate Auth::onceUsingId() for every request until you stop impersonating.
Execute the following command to get the latest version of the package:
composer require bizhub/impersonate
Add CheckIfImpersonating middleware to app\Http\Kernel.php
protected $middlewareGroups = [
'web' => [
// ...
\Bizhub\Impersonate\Middleware\CheckIfImpersonating::class,
]
];
Add CanImpersonate trait to your User model
namespace App;
use Bizhub\Impersonate\Traits\CanImpersonate;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use CanImpersonate;
// ...
}
// Retrieve your user model
$user = User::find(1);
// Start impersonating
$user->impersonate();
// Redirect/reload the page
// ...
// Stop impersonating
Auth::user()->stopImpersonating();