Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Impersonate Laravel Package

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().

View on GitHub
Deep Wiki
Context7

Laravel-Impersonate

A simple Laravel Package to temporarily login as other users.

Usage

You can login to another user through {app_url}/impersonate/login/{user_id}.

And you can end the session with {app_url}/impersonate/logout.

Install Package

composer require j84115/impersonate Not yet on Packagist. Install manually.

Add Sevice Provider

Add the Package to config/app.php

J84115\Impersonate\ImpersonateServiceProvider::class,

Add Interface To User

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';
    }

Routing

Add the following macro to your routes. Typically guarded with auth Middleware in routes/web.php.

Route::impersonate();
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log