Skip to content

Instantly share code, notes, and snippets.

@marventhieme
marventhieme / EventServiceProvider.php
Created April 5, 2024 09:06
Laravel Jetstream/Fortify/Inertia: Impersonate a user (Basic implementation)
public function boot(): void
{
// Build out the impersonation event listeners - Otherwise we get a redirect to login if not setting the password_hash_sanctum when using sanctum.
Event::listen(function (TakeImpersonation $event) {
session()->put([
'password_hash_sanctum' => $event->impersonated->getAuthPassword(),
]);
});
Event::listen(function (LeaveImpersonation $event) {