j84115/impersonate

There is no license information available for the latest version (V0.1.0) of this package.

...

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Open Issues: 0

Type:laravel-package

V0.1.0 2023-03-22 12:11 UTC

This package is auto-updated.

Last update: 2024-09-13 14:32:03 UTC


README

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