A Laravel package to impersonate users
A great feature of Laravel Spark is it's ability to impersonate other users. As an admin you can view all screens as if you are logged in as another user. This allows you to easily spot a problem that your user might be reporting. Laravel-impersonate is a package, made by MarceauKa and Thibault Chazottes that can add this behaviour to any Laravel app.
Here are some code examples taken from the readme.
Auth::user()->impersonate($otherUser); // You're now logged as the $otherUser.
Auth::user()->leaveImpersonation(); // You're now logged as your original user.
$manager = app('impersonate');
// Find an user by its ID
$manager->findUserById($id);
// TRUE if your are impersonating an user.
$manager->isImpersonating();
// Impersonate an user. Pass the original user and the user you want to impersonate
$manager->take($from, $to);
// Leave current impersonation
$manager->leave();
// Get the impersonator ID
$manager->getImpersonatorId();
It even includes some handy blade directives:
@canImpersonate
<a href="{{ route('impersonate', $user->id) }}">Impersonate this user</a>
@endCanImpersonate
@impersonating
<a href="{{ route('impersonate.leave') }}">Leave impersonation</a>
@endImpersonating
Want to know more, take a look at the package on GitHub.
What are your thoughts on "A Laravel package to impersonate users"?