New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

christhompsontldr/impersonate

Allows a user to impersonate another user.
484
Install
composer require christhompsontldr/impersonate
Latest Version:v2.0.0
Last Updated:Oct 13, 2020
Links: GitHub  ·  Packagist
Maintainer: ChrisThompsonTLDR

This Laravel package allows a user to impersonate another user.

Installation

Composer

Require this package with composer:

composer require christhompsontldr/impersonate

Model

Update your user model to be impersonatable.

namespace App\Models;

use Christhompsontldr\Impersonate\Models\Traits\Impersonatable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Impersonatable;

Access Control

You must complete this step, or none of your users will have permission to impersonate.

The authorized users that can impersonate and which users they can impersonate is controlled via the trait. This can be overloaded on your user model

In this example, the user model has an is_admin attribute that is being checked.

public function canImpersonate(User $user)
{
    return $this->is_admin ?: false;
}

Or if you are using Laratrust

public function canImpersonate(User $user)
{
    // can't impersonate other admins
    if ($user->hasRole('admin')) {
        return false;
    }

    // current user is admin
    return $this->hasRole('admin');
}

Issues

Logout will be performed on both the main user and the impersonated user.

Source

This package is based on this example.

Related Packages

laracomponents/impersonation

Impersonating user for Laravel application.

1,044 2
compredict/users-sdk-laravel

Compredict's Users API for laravel.

1,100 0
zaxx44a/laravel-user-management

With this package we can manage all of the users in our project.

60 0
tomatophp/filament-users

Manage your users with a highly customizable user resource for FilamentPHP with...

180,055 91
morilog/acl

Access control list management for Laravel Framework

30 3

Version History

Version Released License
v2.0.0
v1.0.2
v1.0.1
v1.0.0
0.0.4