j84115/impersonate
Simple Laravel package to temporarily impersonate other users via /impersonate/login/{user_id} and /impersonate/logout. Add service provider, implement ImpersonateUser on your User model to define who can impersonate and who can be impersonated, then register Route::impersonate().
A simple Laravel Package to temporarily login as other users.
You can login to another user through {app_url}/impersonate/login/{user_id}.
And you can end the session with {app_url}/impersonate/logout.
Not yet on Packagist. Install manually.composer require j84115/impersonate
Add the Package to config/app.php
J84115\Impersonate\ImpersonateServiceProvider::class,
Add the Interface to your User Model. Typically app/Models/User.php.
use J84115\Impersonate\Interfaces\ImpersonateUser;
Implement the interface.
class User extends Authenticatable implements ImpersonateUser
Then add your conditions for who can impersonate a user.
public function impersonator(): bool
{
return $this->role === 'admin';
}
public function impersonatable(): bool
{
return $this->email !== 'admin';
}
Add the following macro to your routes. Typically guarded with auth Middleware in routes/web.php.
Route::impersonate();
How can I help you explore Laravel packages today?